Exemplo n.º 1
0
        public virtual void Initialize(ServiceProvider 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 == null)
            {
                config = DefaultConfiguration.CreateForRuntimePlatform();
            }

            InitConfiguration(config);

            #endregion Configuration

            #region Application/User Settings

            var appSettings = serviceProvider.GetService <IChromelyAppSettings>();
            if (appSettings == 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 == null)
            {
                logger = new SimpleLogger();
            }

            var defaultLogger = new DefaultLogger();
            defaultLogger.Log = logger;
            Logger.Instance   = defaultLogger;

            #endregion

            EnsureExpectedWorkingDirectory();

            _servicesInitialized = true;
        }
Exemplo n.º 2
0
        public virtual void ConfigureCoreServices(ServiceCollection services)
        {
            if (!_servicesConfigured)
            {
                throw new Exception("Custom services must be configured before core default services are set.");
            }

            // Add core services if not already added.
            // Expected core services are -
            // IChromelyAppSettings, IChromelyConfiguration, IChromelyLogger, IChromelyRouteProvider
            // DefaultAppSettings  DefaultConfiguration SimpleLogger, DefaultRouteProvider
            // Logger is added in Initialize method

            services.TryAddSingleton <IChromelyConfiguration>(DefaultConfiguration.CreateForRuntimePlatform());
            services.TryAddSingleton <IChromelySerializerUtil, DefaultSerializerUtil>();
            services.TryAddSingleton <IChromelyAppSettings, DefaultAppSettings>();

            _coreServicesConfigured = true;
        }
Exemplo n.º 3
0
        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);
        }