public Worker(ILogger <Worker> logger,
               IServiceScopeFactory serviceScopeFactory,
               WorkerSettings settings)
 {
     _logger = logger;
     _serviceScopeFactory = serviceScopeFactory;
     _settings            = settings;
 }
Example #2
0
        public static IHostBuilder CreateHostBuilder(string[] args) =>
        Host.CreateDefaultBuilder(args)
        .ConfigureServices((hostContext, services) =>
        {
            services.AddDbContext(hostContext.Configuration);
            services.AddScoped <ILocationsService, LocationsFileService>();
            services.Configure <LocationsFileServiceConfiguration>(hostContext.Configuration.GetSection("LocationsFileServiceConfiguration"));

            services.AddLogging(logging =>
            {
                logging.ClearProviders();
                logging.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace);
                logging.AddNLog();
            });

            var workerSettings = new WorkerSettings();
            hostContext.Configuration.Bind(nameof(WorkerSettings), workerSettings);
            services.AddSingleton(workerSettings);

            services.AddHostedService <Worker>();
        });