Add EmailSender to dependency injection

master
dan 2019-07-24 22:52:35 -06:00
parent ac04fa1419
commit 41326e1edb
1 changed files with 9 additions and 0 deletions

View File

@ -12,7 +12,9 @@ using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using OFBButte.Application.Configuration; using OFBButte.Application.Configuration;
using OFBButte.Application.Database; using OFBButte.Application.Database;
using OFBButte.Application.Email;
using OFBButte.Database; using OFBButte.Database;
using OFBButte.Infrastructure.Email;
namespace OFBButte.Api namespace OFBButte.Api
{ {
@ -53,6 +55,13 @@ namespace OFBButte.Api
OFBContext.UseMySql(o, Configuration.GetConnectionString("OFBContext")); OFBContext.UseMySql(o, Configuration.GetConnectionString("OFBContext"));
}); });
services.AddScoped<IOFBContext, OFBContext>(s => s.GetService<OFBContext>()); services.AddScoped<IOFBContext, OFBContext>(s => s.GetService<OFBContext>());
// Email Service
services.AddScoped<IEmailSender, EmailSender>(s =>
{
var options = s.GetService<IOptions<AppSettings>>();
return new EmailSender(options.Value.Environment != "Prod");
});
} }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.