public object Create(object parent, object configContext, XmlNode section) { var config = new CMSConfig(); var userAgentStringsNode = section.SelectSingleNode("UserAgentStrings"); config.UserAgentStringsPath = GetString(userAgentStringsNode, "databasePath"); return(config); }
/// <summary> /// Initialize components and plugins in the nop environment. /// </summary> /// <param name="config">Config</param> public void Initialize(CMSConfig config) { //register dependencies RegisterDependencies(config); // register auto mapping tasks RegisterMapperConfiguration(); //startup tasks var settings = ContextHelper.Current.Resolve <DatabaseSettings>(); if (settings != null && settings.IsValid()) { var provider = ContextHelper.Current.Resolve <IDataProvider>(); if (provider == null) { throw new Exception("No IDataProvider found"); } provider.SetDatabaseInitializer(); } }
/// <summary> /// Register dependencies /// </summary> /// <param name="config">Config</param> protected virtual void RegisterDependencies(CMSConfig config) { var builder = new ContainerBuilder(); var container = builder.Build(); this._containerManager = new ContainerManager(container); //we create new instance of ContainerBuilder //because Build() or Update() method can only be called once on a ContainerBuilder. //dependencies var typeFinder = new WebAppTypeFinder(); builder = new ContainerBuilder(); builder.RegisterInstance(config).As <CMSConfig>().SingleInstance(); builder.RegisterInstance(this).As <IEngine>().SingleInstance(); builder.RegisterInstance(typeFinder).As <ITypeFinder>().SingleInstance(); builder.Update(container); //register dependencies provided by other assemblies builder = new ContainerBuilder(); var drTypes = typeFinder.FindClassesOfType <IDependencyRegistrar>(); var drInstances = new List <IDependencyRegistrar>(); foreach (var drType in drTypes) { drInstances.Add((IDependencyRegistrar)Activator.CreateInstance(drType)); } //sort drInstances = drInstances.AsQueryable().OrderBy(t => t.Order).ToList(); foreach (var dependencyRegistrar in drInstances) { dependencyRegistrar.Register(builder, typeFinder, config); } builder.Update(container); //set dependency resolver DependencyResolver.SetResolver(new AutofacDependencyResolver(container)); }