ServiceLifetime 枚举

定义

指定 IServiceCollection 中服务的生存期。Specifies the lifetime of a service in an IServiceCollection.

public enum class ServiceLifetime
public enum ServiceLifetime
type ServiceLifetime = 
Public Enum ServiceLifetime
继承
ServiceLifetime

字段

Scoped 1

指定将为每个作用域创建服务的新实例。Specifies that a new instance of the service will be created for each scope. 在 ASP.NET Core 应用中,会针对每个服务器请求创建一个作用域。In ASP.NET Core apps, a scope is created around each server request.

Singleton 0

指定将创建该服务的单个实例。Specifies that a single instance of the service will be created.

Transient 2

指定每次请求服务时,将创建该服务的新实例。Specifies that a new instance of the service will be created every time it is requested.

适用于