public static IEngine CreateEngineInstance(Config config) { if (config != null && !string.IsNullOrEmpty(config.Engine.Type)) { var engineType = Type.GetType(config.Engine.Type); if (engineType == null) throw new ConfigurationErrorsException("The type '" + engineType + "' could not be found. Please check the configuration at /configuration/nop/engine[@engineType] or check for missing assemblies."); //if (!typeof(IEngine).IsAssignableFrom(engineType)) if(!engineType.IsInheritFrom(typeof(IEngine))) throw new ConfigurationErrorsException("The type '" + engineType + "' doesn't implement 'Nop.Core.Infrastructure.IEngine' and cannot be configured in /configuration/nop/engine[@engineType] for that purpose."); //return Activator.CreateInstance(engineType) as IEngine; return EmitHelper.FastGetInstance(engineType)() as IEngine; } return new Engine(); }
/// <summary> /// register necessary type /// </summary> /// <param name="engine"></param> /// <param name="containerManager"></param> /// <param name="broker"></param> /// <param name="configuration"></param> public virtual void Init(IEngine engine, IContainerManager containerManager, EventBroker broker, Config configuration) { // register singleton instance containerManager.AddComponentInstance<Config>(configuration, typeof(Config).Name); containerManager.AddComponentInstance<IEngine>(engine, engine.GetType().Name); containerManager.AddComponentInstance<EventBroker>(broker, broker.GetType().Name); containerManager.AddComponentInstance<ContainerConfigBase>(this, this.GetType().Name); // register type containerManager.AddComponent<ISearcher, WebsiteSearcher>(typeof(WebsiteSearcher).Name); // register type: should remove in future (to use configuration provider to config and register) // TO-DO: Check if I register this time multi times (should not) //containerManager.AddComponent<DatabaseSettings>(typeof(DatabaseSettings).Name); // to remove because data dll has been decoupled // TO-DO: Check if register it before and figure out how to set it containerManager.AddComponentInstance<StoreStateSettings>( new StoreStateSettings { DefaultStoredThemeForDesktop = "Default", DefaultStoredThemeForMobile = "Default", EnableMiniProfile = true }, typeof(StoreStateSettings).Name); containerManager.AddComponentInstance<UserSettings>(new UserSettings { StoreLastVisitedPage = true, UsingUserEmail = true }, typeof(UserSettings).Name); // TO-DO: Check if register it before and figure out how to set it containerManager.AddComponentInstance<PageSettings>(new PageSettings { DefaultTitle = "HomePage" }, typeof(PageSettings).Name, Infrastructure.IoC.LifeStyle.Singleton); // register IRegistrar containerManager.UpdateContainer(build => { var searcher = containerManager.Resolve<ISearcher>(typeof(WebsiteSearcher).Name); searcher.RoutingToExecute<IRegistrar>(i => i.Register(build, searcher)); }); // TO-DO }
public WebsiteSearcher(Config config) { this.ensureBinFolderAssembliesLoaded = config.Automation.Enabled; }
public ThemeProvider(Config config) { this.themeConfigurations = new List<ThemeConfig>(); // set empty this.themeConfigPath = WebsiteHelper.MapPath(config.Themes.BasePath); // if Themes.BasePath is not set, will return empty LoadConfiguration(this.themeConfigPath); }
public override void Init(IEngine engine, IContainerManager containerManager, Infrastructure.EventBroker broker, Config configuration) { base.Init(engine, containerManager, broker, configuration); }