/// <summary> /// Creates/initializes common infrastructure objects [Configuration, Logging, AppSetting] that are not previously added to <see cref="IServiceCollection" />. /// <remarks> /// Note: the objects [Configuration, Logging, AppSetting] will only be created/initialized if not added in: /// - ConfigureCoreServices /// - CoreServices /// - ConfigureServices /// </remarks> /// </summary> /// <param name="serviceProvider">The <see cref="IServiceProvider"/> for application services.</param> /// <exception cref="Exception"></exception> public virtual void Initialize(IServiceProvider serviceProvider) { if (!_servicesConfigured || !_coreServicesConfigured || !_resolversConfigured || !_defaultHandlersConfigured) { throw new Exception("Services must be configured before application is initialized."); } #region Configuration var config = serviceProvider.GetService <IChromelyConfiguration>(); if (config is null) { config = DefaultConfiguration.CreateForRuntimePlatform(); } ChromelyApp.InitConfiguration(config); #endregion Configuration #region Application/User Settings var appSettings = serviceProvider.GetService <IChromelyAppSettings>(); if (appSettings is null) { appSettings = new DefaultAppSettings(); } var currentAppSettings = new CurrentAppSettings { Properties = appSettings }; ChromelyAppUser.App = currentAppSettings; ChromelyAppUser.App.Properties.Read(config); #endregion #region Logger var logger = GetCurrentLogger(serviceProvider); if (logger is null) { logger = new SimpleLogger(); } var defaultLogger = new DefaultLogger { Log = logger }; Logger.Instance = defaultLogger; #endregion EnsureExpectedWorkingDirectory(); _servicesInitialized = true; }
public virtual void Initialize(IChromelyContainer container, IChromelyAppSettings appSettings, IChromelyConfiguration config, IChromelyLogger chromelyLogger) { EnsureExpectedWorkingDirectory(); #region Container _container = container; if (_container == null) { _container = new SimpleContainer(); } #endregion #region Configuration if (config == null) { var configurator = new ConfigurationHandler(); config = configurator.Parse <DefaultConfiguration>(); } if (config == null) { config = DefaultConfiguration.CreateForRuntimePlatform(); } InitConfiguration(config); config.Platform = ChromelyRuntime.Platform; #endregion #region Application/User Settings if (appSettings == null) { appSettings = new DefaultAppSettings(config.AppName); } var currentAppSettings = new CurrentAppSettings(); currentAppSettings.Properties = appSettings; ChromelyAppUser.App = currentAppSettings; ChromelyAppUser.App.Properties.Read(config); #endregion #region Logger if (chromelyLogger == null) { chromelyLogger = new SimpleLogger(); } var defaultLogger = new DefaultLogger(); defaultLogger.Log = chromelyLogger; Logger.Instance = defaultLogger; #endregion // Register all primary objects _container.RegisterInstance(typeof(IChromelyContainer), typeof(IChromelyContainer).Name, _container); _container.RegisterInstance(typeof(IChromelyAppSettings), typeof(IChromelyAppSettings).Name, appSettings); _container.RegisterInstance(typeof(IChromelyConfiguration), typeof(IChromelyConfiguration).Name, config); _container.RegisterInstance(typeof(IChromelyLogger), typeof(IChromelyLogger).Name, chromelyLogger); }
public virtual void Initialize(IServiceCollection container, IChromelyAppSettings appSettings, IChromelyConfiguration config, IChromelyLogger chromelyLogger) { EnsureExpectedWorkingDirectory(); #region Container _container = container; if (_container == null) { _container = new ServiceCollection(); } #endregion #region Configuration if (config == null) { var configurator = new ConfigurationHandler(); config = configurator.Parse <DefaultConfiguration>(); } if (config == null) { config = DefaultConfiguration.CreateForRuntimePlatform(); } InitConfiguration(config); config.Platform = ChromelyRuntime.Platform; #endregion #region Application/User Settings if (appSettings == null) { appSettings = new DefaultAppSettings(config.AppName); } var currentAppSettings = new CurrentAppSettings(); currentAppSettings.Properties = appSettings; ChromelyAppUser.App = currentAppSettings; ChromelyAppUser.App.Properties.Read(config); #endregion #region Logger if (chromelyLogger == null) { chromelyLogger = new SimpleLogger(); } var defaultLogger = new DefaultLogger(); defaultLogger.Log = chromelyLogger; Logger.Instance = defaultLogger; #endregion // Register all primary objects _container.AddSingleton <IChromelyContainer>(new ChromelyServiceCollectionContainer(_container)); _container.AddSingleton(_container); _container.AddSingleton(appSettings); _container.AddSingleton(config); _container.AddSingleton(chromelyLogger); _container.AddSingleton(NativeHostFactory.GetNativeHost(config)); _container.AddChromelyMvcWithDefaultRoutes(); }