相关文章推荐
伤情的香菜  ·  Installation ...·  5 月前    · 
爱听歌的夕阳  ·  python - ...·  1 年前    · 
温暖的海豚  ·  PHP:guzzlehttp/guzzle发 ...·  1 年前    · 
非常酷的黄豆  ·  Shiny Dashboard Structure·  1 年前    · 
坏坏的抽屉  ·  VMware Knowledge Base·  1 年前    · 
public static void AddTestTran( this IServiceCollection service) {
service.AddTransient<ITranTest, TranTest>();
service.AddSingleton<ISingTest, SingTest>();
service.AddScoped<ISconTest, SconTest>();
service.AddScoped<IAService, AService>();
public class AService: IAService
private ISingTest sing; ITranTest tran; ISconTest scon;
public AService(ISingTest sing, ITranTest tran, ISconTest scon)
this .sing = sing;
this .tran = tran;
this .scon = scon;
public void RedisTest()

AddScoped的对象没有变化

AddTransient的对象发生变化

------------------------------------------------------------

请求get

AddSingleton的对象没有变

AddScoped的对象发生变化

AddTransient的对象发生变化

由于AddScoped对象是在请求的时候创建的

所以不能在AddSingleton对象中使用

甚至也不能在AddTransient对象中使用

所以权重为

AddSingleton→AddTransient→AddScoped

不然则会抛如下异常