Prashant.AutoServiceInjection
6.0.3
dotnet add package Prashant.AutoServiceInjection --version 6.0.3
NuGet\Install-Package Prashant.AutoServiceInjection -Version 6.0.3
<PackageReference Include="Prashant.AutoServiceInjection" Version="6.0.3" />
paket add Prashant.AutoServiceInjection --version 6.0.3
#r "nuget: Prashant.AutoServiceInjection, 6.0.3"
// Install Prashant.AutoServiceInjection as a Cake Addin #addin nuget:?package=Prashant.AutoServiceInjection&version=6.0.3 // Install Prashant.AutoServiceInjection as a Cake Tool #tool nuget:?package=Prashant.AutoServiceInjection&version=6.0.3
AutoServiceInjection
A automated service injection for DotNet.
Supported
Tested on .Net6 Only .Net6 is supported. For .Net 5 support, stay on version 6.0.2
Whats New
- Added support for Generics based contract and Service depebdency injection
- Added support for Non contract based Dependency Injection where single object can be injected without any interface.
Architectural pattern
There are two ways of performing automated dependency injections.
- old style, where service is explicitly marked to interface with service type to do dependency injection.
- New Style, where interface is marked with contact and service is marked with serivce type.
New style of standard implies one to one model where a single contract can only have a single service. In this model, the development of a project will faster and quicker. Perfer new style.
New style
In Program.cs
var builder = WebApplication.CreateBuilder(args);
...
...
builder.Services.AutoRegisterServices(); // Add this to enable Auto Dependencies injection. By default old style is disabled.
...
...
Service model
using System;
[Service(ServiceType.Transient)]
public class TheDemoService : IDemo
contract model
using System;
[Contract]
public interface IDemo
Old Style
To enable old style in .Net 6 and .Net 5
builder.Services.AutoRegisterServices(opt => {
opt.EnableBackwardCompatibility = true;
});
Added support for NonContract service injection
using System;
[NonContract]
[Service(ServiceType.Transient)]
public class DemoServiceWithoutContract
Inject service without contract into Dependency injection and call it directly from controller.
using Prashant.AutoServiceInjection;
[Service(typeof(IDemo),ServiceType.Transient)]
public class TheDemoService : IDemo
In startup.cs
using Prashant.AutoServiceInjection;
public void ConfigureServices(IServiceCollection services)
{
....
....
Service.AutoRegister(services,true); //That's all
}
For issues and Sugguestions
Ping me @ https://twitter.com/Prashant_Elango or Drop a mail to software-devision@froze.in
Product | Versions 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. |
-
net6.0
- Microsoft.Extensions.DependencyInjection (>= 6.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.