Skip to content

xljiulang/DependencyInjection.Annotation

Repository files navigation

DependencyInjection.Annotation

基于注解的服务自动查找与注册的DI扩展。使用SourceGenerator无反射,完美支持AOT。

食用步骤

1 nuget引用

<PackageReference Include="DependencyInjection.Annotation" Version="1.1.2" />

2 服务标记

[Service(ServiceLifetime.Singleton)]
class MyService 
{    
}
[Service(ServiceLifetime.Singleton, typeof(IMyService1))]
class MyService : IMyService1
{    
}
[Service(ServiceLifetime.Singleton, typeof(IMyService1), typeof(IMyService2))]
class MyService : IMyService1, IMyService2, IDisposable
{    
}

3 服务注册

builder.Services.Add{AssemblyName}();

其中{AssemblyName}为包含服务的程序集名。

About

基于注解的服务自动查找与注册的DI扩展

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published