public IServiceProvider ConfigureServices(IServiceCollection services) { try { services.AddMvc() .AddJsonOptions(options => { options.SerializerSettings.ContractResolver = new Newtonsoft.Json.Serialization.DefaultContractResolver(); }); services.AddSwaggerGen(options => { options.DefaultLykkeConfiguration("v1", "BcnReports API"); }); var appSettings = Configuration.LoadSettings <GeneralSettings>(); Log = CreateLogWithSlack(services, appSettings); var builder = new AzureBinder().Bind(appSettings, services, Log); builder.Populate(services); ApplicationContainer = builder.Build(); return(new AutofacServiceProvider(ApplicationContainer)); } catch (Exception ex) { Log?.WriteFatalErrorAsync(nameof(Startup), nameof(ConfigureServices), "", ex).Wait(); throw; } }
public void Run() { // Load settings var settingsUrl = Configuration["SettingsUrl"]; if (string.IsNullOrWhiteSpace(settingsUrl)) { // Environment variable "SettingsUrl" with URL to settings file (e.g. "https://settings-dev.lykkex.net/xJNaS5XHZg6DfuUccyKfNcSiiIPMzM1E_WithdrawalRequestScheduler") should exist // You can do that at Project's properties -> Debug -> Environment Variables Console.WriteLine($"''SettingsUrl'' environment variable empty or not found"); return; } var httpClient = new HttpClient(); var response = httpClient.GetAsync(settingsUrl).Result; var settingsString = response.Content.ReadAsStringAsync().Result; var settings = Newtonsoft.Json.JsonConvert.DeserializeObject <AppSettings>(settingsString); var containerBuilder = new AzureBinder().Bind(settings.Settings); var ioc = containerBuilder.Build(); var triggerHost = new TriggerHost(new AutofacServiceProvider(ioc)); triggerHost.ProvideAssembly(GetType().GetTypeInfo().Assembly); var end = new ManualResetEvent(false); AssemblyLoadContext.Default.Unloading += ctx => { Console.WriteLine("SIGTERM recieved"); triggerHost.Cancel(); end.WaitOne(); }; triggerHost.Start().Wait(); end.Set(); }