ASP.NET核心接入等服务这是一个ASP.NET默认核心项目ConfigureServices
方法:使用依赖注入
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
services.AddIdentity<ApplicationUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
services.AddMvc();
// Add application services.
services.AddTransient<IEmailSender, AuthMessageSender>();
services.AddTransient<ISmsSender, AuthMessageSender>();
}
我的问题是我怎么能访问内部ApplicationDbContext电子邮件服务或短信服务?
还是让我们说我将有一个自定义的服务构建和我注册它在DI这样的:
services.AddTransient<ICustomService, CustomService>();
我怎么能访问这里面的电子邮件服务或短信服务?
我认为电子邮件和短信服务必须添加到DI之前,其他服务将使用它们的权利?