示例#1
0
文件: IoC.cs 项目: won21kr/Chromely
 public static void RegisterInstance(Type service, string key, object instance)
 {
     if (m_container != null)
     {
         m_container.RegisterInstance(service, key, instance);
     }
 }
示例#2
0
        public override void Configure(IChromelyContainer container)
        {
            base.Configure(container);

            container.RegisterInstance(typeof(IEventFactory), nameof(IEventFactory), new EventFactory());
            container.RegisterSingleton(
                typeof(ChromelyController),
                nameof(ConfigurationController),
                typeof(ConfigurationController));
        }
示例#3
0
 public static void RegisterCommnandRoutes(IChromelyContainer container, Dictionary <string, CommandRoute> newCommandDictionary)
 {
     if (newCommandDictionary != null && newCommandDictionary.Any())
     {
         foreach (var item in newCommandDictionary)
         {
             container.RegisterInstance(typeof(CommandRoute), item.Key, item.Value);
         }
     }
 }
示例#4
0
        private void RegisterEventHandler <TEventArgs>(
            IChromelyContainer container,
            CefEventKey key,
            Action <object, TEventArgs, IChromelyContainer> handler)
        {
            var service      = CefEventHandlerTypes.GetHandlerType(key);
            var eventHandler = new ChromelyEventHandler <TEventArgs>(key, (s, e) => handler(s, e, container));

            container.RegisterInstance(service, eventHandler.Key, eventHandler);
        }
示例#5
0
        public virtual void Initialize(IChromelyContainer container, IChromelyConfiguration config, IChromelyLogger chromelyLogger)
        {
            EnsureExpectedWorkingDirectory();

            if (config == null)
            {
                var configurator = new ConfigurationHandler();
                config = configurator.Parse <DefaultConfiguration>();
            }

            if (config == null)
            {
                config = new DefaultConfiguration();
            }

            InitConfiguration(config);

            if (chromelyLogger == null)
            {
                chromelyLogger = new SimpleLogger();
            }

            var defaultLogger = new DefaultLogger();

            defaultLogger.Log = chromelyLogger;
            Logger.Instance   = defaultLogger;

            config.Platform = ChromelyRuntime.Platform;

            _container = container;
            if (_container == null)
            {
                _container = new SimpleContainer();
            }

            // Register all primary objects
            _container.RegisterInstance(typeof(IChromelyContainer), typeof(IChromelyContainer).Name, _container);
            _container.RegisterInstance(typeof(IChromelyConfiguration), typeof(IChromelyConfiguration).Name, config);
            _container.RegisterInstance(typeof(IChromelyLogger), typeof(IChromelyLogger).Name, chromelyLogger);
        }
        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);
        }
示例#7
0
 public static void RegisterCommandRoute(IChromelyContainer container, string key, CommandRoute command)
 {
     container.RegisterInstance(typeof(CommandRoute), key, command);
 }
示例#8
0
 public static void RegisterActionRoute(IChromelyContainer container, string key, ActionRoute route)
 {
     container.RegisterInstance(typeof(ActionRoute), key, route);
 }
示例#9
0
        private void RegisterEventHandler <T>(IChromelyContainer container, CefEventKey key, ChromelyEventHandler <T> handler)
        {
            var service = CefEventHandlerTypes.GetHandlerType(key);

            container.RegisterInstance(service, handler.Key, handler);
        }