Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/xljiulang/dependencyinjection.annotation

基于注解的服务自动查找与注册的DI扩展
https://github.com/xljiulang/dependencyinjection.annotation

Last synced: 2 months ago
JSON representation

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

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}为包含服务的程序集名。