EasyServiceRegister 2.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package EasyServiceRegister --version 2.0.1                
NuGet\Install-Package EasyServiceRegister -Version 2.0.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="EasyServiceRegister" Version="2.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add EasyServiceRegister --version 2.0.1                
#r "nuget: EasyServiceRegister, 2.0.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install EasyServiceRegister as a Cake Addin
#addin nuget:?package=EasyServiceRegister&version=2.0.1

// Install EasyServiceRegister as a Cake Tool
#tool nuget:?package=EasyServiceRegister&version=2.0.1                

Version 2.0.0 of EasyServiceRegister has some break changes, code has been optimized and other cool stuff has been added!!

How to use it:

  1. First you will need to install the package in the project where your services implementations will be.
dotnet add package EasyServiceRegister --version 2.0.1 (.net 6 or supperior)
  1. Then in each service class you must add one of the following class attributes:
RegisterAsSingleton  --> It will register your service as Singleton.
RegisterAsScoped    --> It will register your service as Scoped.
RegisterAsTransient --> It will register your service as Transcient.
  1. Finally you must register your services using the following extension method
services.AddServices(params Type[] handlerAssemblyMarkerTypes);

Each handlerAssemblyMarkerTypes must be a type from the assembly where your services are.

Here is an example of a service implementation:

var builder = WebApplication.CreateBuilder(args);

var configuration = builder.Configuration;

// In this case services from two differents assemblies are been registered into IoC 
builder.Services.AddServices(typeof(DependencyInjection), typeof(Program));

builder.Services.AddEndpointDefinitions(configuration);

var app = builder.Build();

app.ConfigurePipeline();

app.UseEndpointDefinitions();

await app.ApplySeeder();

await app.RunAsync();
[RegisterAsScoped]
public class ProductCommandServices : IProductCommandServices
{
    private readonly IApplicationDbContext _context;
    private readonly IMapper _mapper;

    public ProductCommandServices(IApplicationDbContext context, IMapper mapper)
    {
        _context = context;
        _mapper = mapper;
    }
}
[RegisterAsSingleton]
public class GetCurrentUser
{
  public Task<User> GetCurrentUser()
   {
     ...
   }
}

Consider the following: In case your service implement an interface to abstract itself, that interface must be the last you implement. Ex.

[RegisterAsScoped]
 public class ProductCommandServices : ISomeOtherInterface, IProductCommandServices
{
 ...
}

And that's it!! No more loaded Startup classes or huge extension methods registering services in your code. 😃

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.0.9 5,716 12/6/2023
2.0.8 154 12/5/2023
2.0.7 116 12/5/2023
2.0.6 767 4/29/2023
2.0.5 2,610 11/26/2022
2.0.4 316 11/23/2022
2.0.3 345 11/20/2022
2.0.2 320 11/19/2022
2.0.1 302 11/19/2022
2.0.0 312 11/19/2022
1.0.2 2,879 5/8/2022
1.0.1 399 5/8/2022
1.0.0 493 1/19/2022
0.0.9 388 1/20/2022
0.0.8 414 1/20/2022