TanvirArjel.Extensions.Microsoft.DependencyInjection 1.0.1

This is a .NET 5.0 and .NET Core dynamic service registration library that enables you to register all your services into .NET Core Dependency Injection container at once without exposing the service implementation.

This library supports both the marker interface and attribute-based service registration.

For configuration details please visit the GitHub repository.

There is a newer version of this package available.
See the version list below for details.
Install-Package TanvirArjel.Extensions.Microsoft.DependencyInjection -Version 1.0.1
dotnet add package TanvirArjel.Extensions.Microsoft.DependencyInjection --version 1.0.1
<PackageReference Include="TanvirArjel.Extensions.Microsoft.DependencyInjection" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add TanvirArjel.Extensions.Microsoft.DependencyInjection --version 1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: TanvirArjel.Extensions.Microsoft.DependencyInjection, 1.0.1"
For F# scripts that support #r syntax, copy this into the source code to reference the package.
// Install TanvirArjel.Extensions.Microsoft.DependencyInjection as a Cake Addin
#addin nuget:?package=TanvirArjel.Extensions.Microsoft.DependencyInjection&version=1.0.1

// Install TanvirArjel.Extensions.Microsoft.DependencyInjection as a Cake Tool
#tool nuget:?package=TanvirArjel.Extensions.Microsoft.DependencyInjection&version=1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

How do I get started?

First, install the latest version of this NuGet package into your project as follows:

Install-Package TanvirArjel.Extensions.Microsoft.DependencyInjection

Using Marker Interface:

Now let your services to inherit any of the ITransientService, IScoperService, and ISingletonService marker interfaces as follows:

// Inherit `IScopedService` interface if you want to register `IEmployeeService` as scoped service.
public class IEmployeeService : IScopedService
{
   Task CreateEmployeeAsync(Employee employee);
}

internal class EmployeeService : IEmployeeService 
{
  public async Task CreateEmployeeAsync(Employee employee)
  {
    // Implementation here
  };
}

Using Attribute:

Now mark your services with any of the ScopedServiceAttribute, TransientServiceAttribute, and SingletonServiceAttribute attributes as follows:

// Mark with ScopedServiceAttribute if you want to register `IEmployeeService` as scoped service.
[ScopedService]
public class IEmployeeService
{
  Task CreateEmployeeAsync(Employee employee);
}

internal class EmployeeService : IEmployeeService 
{
   public async Task CreateEmployeeAsync(Employee employee)
   {
   // Implementation here
   };
}

Now in your ConfigureServices method of the Startup class:

public static void ConfigureServices(IServiceCollection services)
{
  services.AddServicesOfType<IScopedService>();
  services.AddServicesWithAttributeOfType<ScopedServiceAttribute>();
}

For more documentation details, please visit: GitHub Repository

How do I get started?

First, install the latest version of this NuGet package into your project as follows:

Install-Package TanvirArjel.Extensions.Microsoft.DependencyInjection

Using Marker Interface:

Now let your services to inherit any of the ITransientService, IScoperService, and ISingletonService marker interfaces as follows:

// Inherit `IScopedService` interface if you want to register `IEmployeeService` as scoped service.
public class IEmployeeService : IScopedService
{
   Task CreateEmployeeAsync(Employee employee);
}

internal class EmployeeService : IEmployeeService 
{
  public async Task CreateEmployeeAsync(Employee employee)
  {
    // Implementation here
  };
}

Using Attribute:

Now mark your services with any of the ScopedServiceAttribute, TransientServiceAttribute, and SingletonServiceAttribute attributes as follows:

// Mark with ScopedServiceAttribute if you want to register `IEmployeeService` as scoped service.
[ScopedService]
public class IEmployeeService
{
  Task CreateEmployeeAsync(Employee employee);
}

internal class EmployeeService : IEmployeeService 
{
   public async Task CreateEmployeeAsync(Employee employee)
   {
   // Implementation here
   };
}

Now in your ConfigureServices method of the Startup class:

public static void ConfigureServices(IServiceCollection services)
{
  services.AddServicesOfType<IScopedService>();
  services.AddServicesWithAttributeOfType<ScopedServiceAttribute>();
}

For more documentation details, please visit: GitHub Repository

Release Notes

1. XML comment issue has been fixed.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.3.0 44 4/7/2021
1.2.1 308 3/13/2021
1.2.0 137 3/13/2021
1.0.1 85 2/9/2021
1.0.0 919 10/1/2020