// This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { services.AddEventBusRabbitMQ(builder => { var retryCount = int.Parse(Configuration["EventBusRetryCount"]); builder.ConfigureConnection(con => { con.HostName = Configuration["EventBusConnection"]; con.UserName = Configuration["EventBusUserName"]; con.Password = Configuration["EventBusPassword"]; }); builder.SubscriptionClientName = Configuration["EventBusSubscriptionClientName"]; builder.RetryCount = retryCount; builder.RegisterEventHandler <EmailSendEventHandler>(); }); services.AddSwaggerGen(c => { c.SwaggerDoc(Configuration["SwaggerDocName"], new Info { Title = Configuration["SwaggerDocTitle"], Version = Configuration["SwaggerDocVersion"] }); }); services.AddCors(options => { options.AddPolicy(Configuration["CorsPolicy"], builder => builder.AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader() .AllowCredentials()); }); services.AddTransient <IMailService>(sp => { var smtpProvider = new SmtpProvider { Domain = Configuration["SmtpDomain"], EnableSSL = Configuration.GetValue <bool>("SmtpEnableSSL"), Login = Configuration["SmtpLogin"], Password = Configuration["SmtpPassword"], Port = Configuration.GetValue <int>("SmtpPort"), TimeOut = Configuration.GetValue <int>("SmtpTimeOut") }; var logger = sp.GetRequiredService <ILogger <IMailService> >(); var mailer = new Mailer.MailServices.Mailer(smtpProvider, logger); return(mailer); }); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); }
public MailController(Mailer.MailServices.Mailer mailer) { _mailer = mailer; }