Exemple #1
0
        public static IHostBuilder CreateHostBuilder(string[] args) =>
        Host.CreateDefaultBuilder(args)
        .UseWindowsService()
        .ConfigureAppConfiguration((hostingContext, config) =>
        {
            config.AddEnvironmentVariables(prefix: "WebParser_");
        })
        .ConfigureServices((hostContext, services) =>
        {
            services.AddHostedService <Worker>();

            IConfiguration configuration = hostContext.Configuration;

            AppSecret appSecret = configuration.GetSection(nameof(AppSecret)).Get <AppSecret>();
            if (appSecret == null)
            {
                _logger.Error($"{nameof(appSecret)} is NULL!");
                throw new NullReferenceException($"{nameof(appSecret)} is NULL!");
            }

            services.AddSingleton(appSecret);
        });
Exemple #2
0
 public Worker(ILogger <Worker> logger, AppSecret appSecret)
 {
     _consoleLogger = logger;
     _appSecret     = appSecret;
 }