public static async Task <InitResult> CheckConfigurationAndInit() { var container = StructureMap(); var configurationProvider = container.GetInstance <ConfigurationImplementation>(); var result = await configurationProvider.LoadConfiguration(); if (!result.Success) { return(new InitResult { container = container, ConfigResult = result }); } Log4net(result.Configuration.EnableTrace, false); var log = LoggingProvider.GetLogger <BootStrap>(); log.Info("OctoPlus started..."); var configuration = result.Configuration; OctopusHelper.Init(configuration.OctopusUrl, configuration.ApiKey); log.Info("Created the octopus client"); container.Configure(c => { c.For <IConfiguration>().Use(result.Configuration).Singleton(); c.For <IOctopusHelper>().Use(OctopusHelper.Default).Singleton(); }); log.Info("Set configuration in structuremap"); return(new InitResult { container = container, ConfigResult = result }); }
public static async Task <Tuple <ConfigurationLoadResult, IServiceProvider> > CheckConfigurationAndInit() { var log = LoggingProvider.GetLogger <Program>(); log.Info("Attempting IoC configuration..."); var container = IoC(); log.Info("Attempting configuration load..."); var configurationLoadResult = await ConfigurationProvider.LoadConfiguration(ConfigurationProviderTypes.Json, new LanguageProvider()); //todo: fix this! if (!configurationLoadResult.Success) { log.Error("Failed to load config."); return(new Tuple <ConfigurationLoadResult, IServiceProvider>(configurationLoadResult, container.BuildServiceProvider())); } log.Info("OctoPlus started..."); OctopusHelper.Init(configurationLoadResult.Configuration.OctopusUrl, configurationLoadResult.Configuration.ApiKey); container.AddSingleton <IOctopusHelper>(OctopusHelper.Default); container.AddSingleton <IConfiguration>(configurationLoadResult.Configuration); log.Info("Set configuration in IoC"); var serviceProvider = container.BuildServiceProvider(); //Temporary filth serviceProvider.GetService <IOctopusHelper>().SetCacheImplementation(serviceProvider.GetService <IMemoryCache>(), configurationLoadResult.Configuration.CacheTimeoutInSeconds); var versionChecker = serviceProvider.GetService <IVersionChecker>(); var checkResult = await versionChecker.GetLatestVersion(); if (checkResult.NewVersion) { ShowNewVersionMessage(checkResult, serviceProvider.GetService <ILanguageProvider>()); } return(new Tuple <ConfigurationLoadResult, IServiceProvider>(configurationLoadResult, serviceProvider)); }