Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/xljiulang/dependencyinjection.annotation
基于注解的服务自动查找与注册的DI扩展
https://github.com/xljiulang/dependencyinjection.annotation
Last synced: 2 months ago
JSON representation
基于注解的服务自动查找与注册的DI扩展
- Host: GitHub
- URL: https://github.com/xljiulang/dependencyinjection.annotation
- Owner: xljiulang
- Created: 2023-08-16T10:47:38.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2023-12-04T17:53:45.000Z (about 1 year ago)
- Last Synced: 2024-10-06T04:21:18.562Z (3 months ago)
- Language: C#
- Homepage:
- Size: 77.1 KB
- Stars: 43
- Watchers: 3
- Forks: 6
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# DependencyInjection.Annotation
基于注解的服务自动查找与注册的DI扩展。使用SourceGenerator无反射,完美支持AOT。### 食用步骤
#### 1 nuget引用
```xml```
#### 2 服务标记
```c#
[Service(ServiceLifetime.Singleton)]
class MyService
{
}
``````c#
[Service(ServiceLifetime.Singleton, typeof(IMyService1))]
class MyService : IMyService1
{
}
``````c#
[Service(ServiceLifetime.Singleton, typeof(IMyService1), typeof(IMyService2))]
class MyService : IMyService1, IMyService2, IDisposable
{
}
```#### 3 服务注册
```c#
builder.Services.Add{AssemblyName}();
```
其中{AssemblyName}为包含服务的程序集名。