static IHost CreateHost(Options options) { var t = Host.CreateDefaultBuilder() .ConfigureAppConfiguration((builderContext, configuration) => { IHostEnvironment env = builderContext.HostingEnvironment; Logger.Info($"Hosting environment: {env.EnvironmentName}"); if (ConfigurationManager.ValidateConfig(options.ConfigFile)) { configuration.Sources.Clear(); configuration .AddJsonFile(options.ConfigFile, optional: false, reloadOnChange: false) .AddJsonFile($"config.{env.EnvironmentName}.json", optional: true, reloadOnChange: false); } else { Logger.Error("There was an error with the configuration file"); } }) .ConfigureLogging((ILoggingBuilder logBuilder) => { logBuilder.ClearProviders(); logBuilder.SetMinimumLevel(LogLevel.Trace); logBuilder.AddNLog(options.NLogConfig); }) .ConfigureServices((builderContext, services) => { services.AddHttpClient(); ConfigureInstances(builderContext, services); BackgroundServiceHelper.CreateAndStart <IHEMSCore, HEMSCore>(services); }) .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseKestrel((builderContext, kestrelOptions) => { kestrelOptions.AddServerHeader = false; WebConfig wc = new(); builderContext.Configuration.GetSection("web").Bind(wc); kestrelOptions.ListenLocalhost(wc.Port, builder => { if (!builderContext.HostingEnvironment.IsDevelopment()) { builder.UseHttps(); } }); }); webBuilder.UseStartup <Startup>(); }).Build(); return(t); }
private Tariff[] _tariffs = Array.Empty <Tariff>(); // time sorted array of tariffs that where fetched public static void ConfigureServices(HostBuilderContext hostContext, IServiceCollection services, Instance instance) { BackgroundServiceHelper.CreateAndStart <IPriceProvider, EPEXSPOT>(services, instance.Config); }