This is an ASP.NET Core default project ConfigureServices method:
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>();
}
My question is how can I access the email service or sms service inside ApplicationDbContext?
Or let's say I will have a custom service built and I register it in the DI like this:
services.AddTransient<ICustomService, CustomService>();
how can I access email service or sms service inside of this?
I assume that the email and sms service must be added to the DI before other services that will use them right?