草庐IT

AddScoped

全部标签

c# - 在 Startup.cs 之外实现依赖注入(inject)

我想在ASP.NETCORE1中实现依赖注入(inject)。我知道.NetCore中的一切都是关于DI的。例如publicvoidConfigureServices(IServiceCollectionservices){//Addapplicationservices.services.AddTransient();}但是对于拥有超过20个实体和服务的大项目来说,在ConfigureServices中编写所有这些代码行是非常困难和不可读的。我想知道这是否可能在Startup.cs之外实现依赖注入(inject),然后将其添加到服务中。感谢您的回答。 最佳

c# - AddTransient、AddScoped 和 AddSingleton 服务差异

我想实现dependencyinjectionASP.NETCore中的(DI)。因此,将此代码添加到ConfigureServices方法后,两种方式都有效。ASP.NETCore中的services.AddTransient和service.AddScoped方法有什么区别?publicvoidConfigureServices(IServiceCollectionservices){//Addframeworkservices.//Addapplicationservices.services.AddTransient();services.AddScoped();}