コード例 #1
0
 public Task Configure(SettingsConfiguration configuration)
 {
     return(Task.CompletedTask);
 }
コード例 #2
0
        protected virtual async Task Start(IDictionary <string, object> settings, string environment, IDictionary <string, string[]> hostArguments)
        {
            var stopwatch = Stopwatch.StartNew();

            Environment            = settings;
            ApplicationEnvironment = environment;

            var basePath = AppDomain.CurrentDomain.BaseDirectory;

            if (!basePath.EndsWith("\\"))
            {
                basePath = $"{basePath}\\";
            }

            settings[ConfigurationsEnvironmentExtensions.ConfigurationConstants.ResolvePathFunc] =
                (Func <string, string>)(x => x.Replace("~", basePath));

            settings[ConfigurationsEnvironmentExtensions.ConfigurationConstants.GetConfigSettings] =
                (Func <Type, object>)GetSettings;

            settings[ConfigurationsEnvironmentExtensions.ConfigurationConstants.GetChainSettingsKey] =
                (Func <string, ChainSettings>)GetChainSettings;

            settings[ConfigurationsEnvironmentExtensions.ConfigurationConstants.GetChain] =
                (Func <string, Action <IBuildAppFunction>, Task <AppFunc> >)GetChain;

            settings[ConfigurationsEnvironmentExtensions.ConfigurationConstants.ApplicationName] = ApplicationName;

            settings[ConfigurationsEnvironmentExtensions.ConfigurationConstants.GetTagsKey] =
                (Func <IEnumerable <string> >)GetApplicationTags;

            var assemblies = LoadApplicationAssemblies().ToList();

            _setups = FindConfigurationSetups(assemblies, environment);

            await RunConfigurations(_setups, environment, x => x.StartupAction(Environment)).ConfigureAwait(false);

            var settingsConfiguration = new SettingsConfiguration(GetSettings, settings, environment);

            await RunConfigurations(_setups, environment, x => x.ConfigureAction(settingsConfiguration))
            .ConfigureAwait(false);

            var serviceResolver = settings.Get <IResolveServices>(SetupIocConfiguration.ServiceResolverKey);

            var chainDefiners = serviceResolver.ResolveAll <IDefineChain>();

            foreach (var chainDefiner in chainDefiners)
            {
                await AddChain(chainDefiner.Name, chainDefiner.Define, chainDefiner.AlterSettings).ConfigureAwait(false);
            }

            await Configure(environment).ConfigureAwait(false);

            _appStarters = serviceResolver
                           .ResolveAll <IStartApplication>()
                           .ToList();

            await BeforeApplicationStart(settings, _appStarters, hostArguments).ConfigureAwait(false);

            settings["superglue.ApplicationStarters"] = _appStarters;

            await RunStarters(_appStarters, hostArguments).ConfigureAwait(false);

            await settings.Publish(ConfigurationEvents.AfterApplicationStart).ConfigureAwait(false);

            stopwatch.Stop();

            Environment.Log("Bootstrapping done in {0} ms", LogLevel.Debug, stopwatch.Elapsed.TotalMilliseconds);

            await
            Environment.PushDiagnosticsData(DiagnosticsCategories.Setup, DiagnosticsTypes.Bootstrapping, "Init",
                                            new Tuple <string, IDictionary <string, object> >("ApplicationsStarted", new Dictionary <string, object>
            {
                { "ExecutionTime", stopwatch.Elapsed },
                { "Environment", environment },
                { "ApplicationName", ApplicationName }
            })).ConfigureAwait(false);
        }