Пример #1
0
        public static IHostBuilder CreateHostBuilder(string[] args)
        {
            return(Host.CreateDefaultBuilder(args)
                   .UseServiceProviderFactory(new AutofacServiceProviderFactory())
                   .UseWindowsService()
                   .ConfigureServices((hostContext, services) =>
            {
                IConfiguration configuration = hostContext.Configuration;
                services.AddHostedService <Worker>();

                SeriLogSettings seriLogSettings = new SeriLogSettings();
                configuration.Bind("SeriLog", seriLogSettings);
                services.AddSingleton(seriLogSettings);

                WorkerSettings workerSettings = new WorkerSettings();
                configuration.Bind("WorkerSettings", workerSettings);
                services.AddSingleton(workerSettings);

                SMTPServerSettings smtpServerSettings = new SMTPServerSettings();
                configuration.Bind("SMTPServerSettings", smtpServerSettings);
                services.AddSingleton(smtpServerSettings);

                MailAppSettings mailAppSettings = new MailAppSettings();
                configuration.Bind("MailAppSettings", mailAppSettings);
                services.AddSingleton(mailAppSettings);

                services.AddDbContext <AppDbContext>(cnf => cnf.UseSqlServer(configuration.GetConnectionString("DBConString")));
            })
                   .ConfigureContainer <ContainerBuilder>((hostContext, builder) =>
            {
                IConfiguration configuration = hostContext.Configuration;
                builder.RegisterModule(new SharedKernelModule(configuration));
                builder.RegisterModule(new CoreModule(configuration));
                builder.RegisterModule(new InfrastructureModule(configuration));
            }));
        }
Пример #2
0
 public EmailServices(IOptions <Options> settings)
 {
     this.settings = settings.Value.SMTPServerSettings;
 }