UseDIAttribute Class

指示一个类可用于依赖注入,并可设置生命周期和一个或多个服务类型(服务类型通常为类所实现的接口)。此特性只可应用于类。

Definition

Namespace: QuickAdmin.Common
Assembly: QuickAdmin.Net (in QuickAdmin.Net.dll) Version: 1.2.4
C#
public class UseDIAttribute : Attribute
Inheritance
object    Attribute    UseDIAttribute

Remarks

生命周期默认为 Singleton
通常如果你的服务直接或间接实现了多个接口,需要通过 [UseDI] 特性来指定要注册的是哪一个接口。
C#
[UseDI(ServiceLifetime.Transient)]
public class MyService : xxx { }

[UseDI(typeof(xxx), typeof(yyy))]
public class MyService : xxx { }

[UseDI(ServiceLifetime.Transient, typeof(xxx))]
public class MyService : xxx { }
参见 AddServicesFromAssemblyExceptNotUseDIs(IServiceCollection, Assembly, string, ServiceLifetime, Func<Type, bool>) 扩展方法。

Constructors

UseDIAttribute(Type[]) 使用 Singleton 生命周期以及指定的服务类型初始化实例。
UseDIAttribute(ServiceLifetime, Type[]) 使用指定的生命周期以及指定的服务类型初始化实例。

Properties

Public Properties

Lifetime 获取要注册的服务的生命周期。
ServiceTypes 获取要注册的服务类型数组。

See Also