在Asp.Net core中的IServiceCollection容器中注册服务的生命周期分以下3种:
1、Transient
通过AddTransient注册,会在IServiceCollection容器每次被请求时创建实例。
2、Scoped
通过AddScoped注册,会在每次客户端请求时创建实例
3、Singleton
通过AddSingleton注册,会在第一次被请求时创建实例,之后的每个请求都会使用这个实例
2022-09-28 22:21:07
在Asp.Net core中的IServiceCollection容器中注册服务的生命周期分以下3种:
1、Transient
通过AddTransient注册,会在IServiceCollection容器每次被请求时创建实例。
2、Scoped
通过AddScoped注册,会在每次客户端请求时创建实例
3、Singleton
通过AddSingleton注册,会在第一次被请求时创建实例,之后的每个请求都会使用这个实例