Antelcat.DependencyInjectionEx
8.1.0
dotnet add package Antelcat.DependencyInjectionEx --version 8.1.0
NuGet\Install-Package Antelcat.DependencyInjectionEx -Version 8.1.0
<PackageReference Include="Antelcat.DependencyInjectionEx" Version="8.1.0" />
paket add Antelcat.DependencyInjectionEx --version 8.1.0
#r "nuget: Antelcat.DependencyInjectionEx, 8.1.0"
// Install Antelcat.DependencyInjectionEx as a Cake Addin #addin nuget:?package=Antelcat.DependencyInjectionEx&version=8.1.0 // Install Antelcat.DependencyInjectionEx as a Cake Tool #tool nuget:?package=Antelcat.DependencyInjectionEx&version=8.1.0
Antelcat.DependencyInjectionEx
Rebuild from Microsoft.Extensions.DependencyInjection
Antelcat.DependencyInjectionEx
Export service resolve callback
BuildServiceProviderEx(this IServiceCollection, ...)
class ServiceProviderEx : IServiceProvider;
ServiceProviderEx provider = new ServiceCollection()
.Add...(...)
...
.BuildServiceProviderEx(options...);
ServiceProviderOptions
ListenKind
indicates which kind of behavior to be listenenum ServiceResolvedKind{ None = 0, // nothing Factory = 1, // service resolved from Func<...> Constructor = 2, // service resolved by ctor Constant = 4, // service resolved from registered instance IEnumerable = 8, // service required by IEnumerable<> ServiceProvider = 16, // require IServiceProvider }
CallbackTime
indicates when should theServiceResolved
be triggeredpublic enum CallbackTime { Finally, // ServiceResolved will be triggered before GetService() returned Immediately, // ServiceResolved will be triggered after each instance resolved }
Finally
Moderesolve A ⇒ resolve B ⇒ resolve C ⇒ trigger A ⇒ trigger B ⇒ trigger C
finally mode can resolve circular dependency
Immediately
Moderesolve A ⇒ trigger A ⇒ resolve B ⇒ trigger B ⇒ resolve C ⇒ trigger C
immediately mode can let dependency full-filled before injected
ServiceProviderEx.ServiceResolved
event to be triggered when service resolved
delegate void ServiceResolvedHandler(
IServiceProvider provider, // service provider which resolved this service
Type serviceType, // required service type
object instance, // resolved instance
ServiceResolveKind kind // resolved kind
);
provider.ServiceResolved += (provider, serviceType, instance, kind) => {
// do something
};
Antelcat.DependencyInjectionEx.Autowired.Abstraction
AutowiredAttribute
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
public class AutowiredAttribute(Type? serviceType = null) : Attribute
{
public object? Key { get; set; } // key for keyed service
public bool GetServices { get; set; } // IEnumerable<...>
}
Usage
class Service{
[Autowired]
private IService? service;
[Autowired(typeof(IService))]
public Service service { get; init; }
[Autowired(typeof(IService), Key="string key", GetServices=true)]
public IEnumerable<Service> keyedService { get; init; }
}
Antelcat.DependencyInjectionEx.Autowired
Auto inject service from props/fields which marked with AutowiredAttribute
IServiceCollection collection; // from somewhere
IServiceProvider provider = collection.BuildAutowiredServiceProviderEx();
Antelcat.AspNetCore.DependencyInjectionEx.Autowired
Autowired service provider for ASP.NET
var builder = WebApplication.CreateBuilder(args);
... multiple configures ...
builder.Host.UseAutowiredServiceProviderFactory(); // should be configured before Build()
var app = builder.Build();
if you want to use AutowiredAttribute
in Controller
remember to
builder.Services.AddControllers()
.AddControllersAsServices(); // register controllers as services
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. 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 is compatible. 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 is compatible. 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. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
.NET Framework | net461 was computed. net462 is compatible. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.6.2
- Microsoft.Bcl.AsyncInterfaces (>= 8.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.0)
- System.Threading.Tasks.Extensions (>= 4.5.4)
-
.NETStandard 2.0
- Microsoft.Bcl.AsyncInterfaces (>= 8.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.0)
- System.Threading.Tasks.Extensions (>= 4.5.4)
-
.NETStandard 2.1
-
net6.0
-
net7.0
-
net8.0
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Antelcat.DependencyInjectionEx:
Package | Downloads |
---|---|
Antelcat.DependencyInjectionEx.Autowired
Autowired Dependency Injection |
GitHub repositories
This package is not used by any popular GitHub repositories.
Autowired type filter