美文网首页
Microsoft DI中的三个注册方法

Microsoft DI中的三个注册方法

作者: 魔人健太郎 | 来源:发表于2021-03-25 16:32 被阅读0次

优先顺序从上至下
AddTransient<>();
AddScoped<>();
AddSingleton<>();

使用注意!
用AddTransient或AddSingleton
AddScoped 不是给注入构造器用的

使用建议
infrustruction(基础设施)如eventBus,windowManager,Apiserver建议用Singleton
无状态的service才考虑AddTransient

相关文章

网友评论

      本文标题:Microsoft DI中的三个注册方法

      本文链接:https://www.haomeiwen.com/subject/exkrhltx.html