AddTransient,AddScoped和AddSingleton服务的差异?
我想要实现dependency injection
在Asp.Net Core
。因此,在将此代码添加到ConfigureServices
方法之后,两种方式都有效。
services.AddTransient
和service.AddScoped
方法有Asp.Net Core
什么区别?
public void ConfigureServices(IServiceCollection services){ // Add framework services. // Add application services. services.AddTransient<IEmailSender, AuthMessageSender>(); services.AddScoped<IEmailSender, AuthMessageSender>();}