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之前,其他服務將使用它們的權利?