Пример #1
0
        /// <summary>
        /// Initialize components and plugins in the nop environment.
        /// </summary>
        /// <param name="config">Config</param>
        public void Initialize(WebCoreConfig config)
        {
            _config = config;
            //register dependencies
            RegisterDependencies(config);

            //startup tasks
            if (!config.IgnoreStartupTasks)
            {
                RunStartupTasks();
            }
        }
Пример #2
0
        /// <summary>
        /// Creates a factory instance and adds a http application injecting facility.
        /// </summary>
        /// <param name="config">Config</param>
        /// <returns>New engine instance</returns>
        protected static IEngine CreateEngineInstance(WebCoreConfig config)
        {
            if (config != null && !string.IsNullOrEmpty(config.EngineType))
            {
                var engineType = Type.GetType(config.EngineType);
                if (engineType == null)
                {
                    throw new ConfigurationErrorsException("The type '" + config.EngineType + "' could not be found. Please check the configuration at /configuration/nop/engine[@engineType] or check for missing assemblies.");
                }
                if (!typeof(IEngine).IsAssignableFrom(engineType))
                {
                    throw new ConfigurationErrorsException("The type '" + engineType + "' doesn't implement 'Infrastructure.Web.Infrastructure.IEngine' and cannot be configured in /configuration/nop/engine[@engineType] for that purpose.");
                }
                return(Activator.CreateInstance(engineType) as IEngine);
            }

            return(new WebEngine());
        }
Пример #3
0
 public WebAppTypeFinder(WebCoreConfig config)
 {
     this._ensureBinFolderAssembliesLoaded = config.DynamicDiscovery;
 }
Пример #4
0
        /// <summary>
        /// Register dependencies
        /// </summary>
        /// <param name="config">Config</param>
        protected virtual void RegisterDependencies(WebCoreConfig config)
        {
            var builder   = new ContainerBuilder();
            var container = builder.Build();

            //we create new instance of ContainerBuilder
            //because Build() or Update() method can only be called once on a ContainerBuilder.


            //dependencies
            var typeFinder = new WebAppTypeFinder(config);

            builder = new ContainerBuilder();
            builder.RegisterInstance(config).As <WebCoreConfig>().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);
            }
            builder.Update(container);



            builder = new ContainerBuilder();
            drTypes = typeFinder.FindClassesOfType <IDependency>();
            foreach (var item in drTypes)
            {
                if (item.IsGenericType)
                {
                    continue;
                }
                // if (item.Name.IndexOf("Service") < 0 || item.Name.IndexOf("BaseService") >= 0) { continue; }
                var temp = builder.RegisterType(item);
                foreach (var it in item.GetInterfaces().Where(itf => typeof(IDependency).IsAssignableFrom(itf)).Reverse())
                {
                    temp.As(it).InstancePerLifetimeScope();
                    //break;
                }
            }

            builder.Update(container);

            //DatabaseInitialize(typeFinder.GetAssemblies());

            this._containerManager = new ContainerManager(container);

            //set dependency resolver
            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
        }
Пример #5
0
        /// <summary>
        /// Creates a configuration section handler.
        /// </summary>
        /// <param name="parent">Parent object.</param>
        /// <param name="configContext">Configuration context object.</param>
        /// <param name="section">Section XML node.</param>
        /// <returns>The created section handler object.</returns>
        public object Create(object parent, object configContext, XmlNode section)
        {
            var config = new WebCoreConfig();
            var dynamicDiscoveryNode = section.SelectSingleNode("DynamicDiscovery");

            if (dynamicDiscoveryNode != null && dynamicDiscoveryNode.Attributes != null)
            {
                var attribute = dynamicDiscoveryNode.Attributes["Enabled"];
                if (attribute != null)
                {
                    config.DynamicDiscovery = Convert.ToBoolean(attribute.Value);
                }
            }

            var engineNode = section.SelectSingleNode("Engine");

            if (engineNode != null && engineNode.Attributes != null)
            {
                var attribute = engineNode.Attributes["Type"];
                if (attribute != null)
                {
                    config.EngineType = attribute.Value;
                }
            }

            var startupNode = section.SelectSingleNode("Startup");

            if (startupNode != null && startupNode.Attributes != null)
            {
                var attribute = startupNode.Attributes["IgnoreStartupTasks"];
                if (attribute != null)
                {
                    config.IgnoreStartupTasks = Convert.ToBoolean(attribute.Value);
                }
            }

            var themeNode = section.SelectSingleNode("Themes");

            if (themeNode != null && themeNode.Attributes != null)
            {
                var attribute = themeNode.Attributes["basePath"];
                if (attribute != null)
                {
                    config.ThemeBasePath = attribute.Value;
                }
            }

            var userAgentStringsNode = section.SelectSingleNode("UserAgentStrings");

            if (userAgentStringsNode != null && userAgentStringsNode.Attributes != null)
            {
                var attribute = userAgentStringsNode.Attributes["databasePath"];
                if (attribute != null)
                {
                    config.UserAgentStringsPath = attribute.Value;
                }
            }

            var SupperUser = section.SelectSingleNode("SupperUser");

            if (SupperUser != null)
            {
                config.SupperUser = SupperUser.InnerText;
            }

            return(config);
        }