예제 #1
0
        /// <summary>
        /// 初始化
        /// </summary>
        /// <param name="config">Config</param>
        public void Initialize(FarmConfig config)
        {
            //依赖注入
            RegisterDependencies(config);

            //startup tasks
            if (!config.IgnoreStartupTasks)
            {
                RunStartupTasks();
            }
        }
예제 #2
0
 /// <summary>
 /// 创建EngineContext实例
 /// </summary>
 /// <param name="config">FarmConfi</param>
 /// <returns>IEngine</returns>
 protected static IEngine CreateEngineInstance(FarmConfig 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 'Nop.Core.Infrastructure.IEngine' and cannot be configured in /configuration/nop/engine[@engineType] for that purpose.");
         return Activator.CreateInstance(engineType) as IEngine;
     }
     return new FarmEngine();
 }
예제 #3
0
        /// <summary>
        /// 创建Config
        /// </summary>
        /// <param name="parent"></param>
        /// <param name="configContext"></param>
        /// <param name="section"></param>
        /// <returns></returns>
        public object Create(object parent, object configContext, XmlNode section)
        {
            var config = new FarmConfig();
            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");
            var userAgentStringsNode = section.SelectSingleNode("UserAgentStrings");

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

            return(config);
        }
예제 #4
0
 /// <summary>
 /// 创建EngineContext实例
 /// </summary>
 /// <param name="config">FarmConfi</param>
 /// <returns>IEngine</returns>
 protected static IEngine CreateEngineInstance(FarmConfig 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 'Nop.Core.Infrastructure.IEngine' and cannot be configured in /configuration/nop/engine[@engineType] for that purpose.");
         }
         return(Activator.CreateInstance(engineType) as IEngine);
     }
     return(new FarmEngine());
 }
예제 #5
0
        /// <summary>
        /// 创建Config
        /// </summary>
        /// <param name="parent"></param>
        /// <param name="configContext"></param>
        /// <param name="section"></param>
        /// <returns></returns>
        public object Create(object parent,object configContext,XmlNode section)
        {
            var config = new FarmConfig();
            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");
            var userAgentStringsNode = section.SelectSingleNode("UserAgentStrings");
            if (userAgentStringsNode != null && userAgentStringsNode.Attributes != null)
            {
                var attribute = userAgentStringsNode.Attributes["databasePath"];
                if (attribute != null)
                    config.UserAgentStringsPath = attribute.Value;
            }

            return config;
        }
예제 #6
0
        /// <summary>
        /// 依赖注入
        /// </summary>
        /// <param name="config">Config</param>
        protected virtual void RegisterDependencies(FarmConfig config)
        {
            //创建依赖容器
            var builder    = new ContainerBuilder();
            var container  = builder.Build();
            var typeFinder = new WebAppTypeFinder(config);

            builder = new ContainerBuilder();
            //注入Config,IEngine,ItypeFinder实例
            builder.RegisterInstance(config).As <FarmConfig>().SingleInstance();
            builder.RegisterInstance(this).As <IEngine>().SingleInstance();
            builder.RegisterInstance(typeFinder).As <ITypeFinder>().SingleInstance();
            builder.Update(container);

            //注入另外程序集的依赖注入提供者
            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);


            this._containerManager = new ContainerManager(container);

            //set dependency resolver
            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
        }
예제 #7
0
        private bool _ensureBinFolderAssembliesLoaded = true; //是否动态加载

        #endregion Fields

        #region Constructors

        /// <summary>
        /// 实例化WebTypeFinder
        /// </summary>
        /// <param name="config">FarmConfig配置</param>
        public WebAppTypeFinder(FarmConfig config)
        {
            this._ensureBinFolderAssembliesLoaded = config.DynamicDiscovery;
        }
예제 #8
0
 /// <summary>
 /// 实例化WebTypeFinder
 /// </summary>
 /// <param name="config">FarmConfig配置</param>
 public WebAppTypeFinder(FarmConfig config)
 {
     this._ensureBinFolderAssembliesLoaded = config.DynamicDiscovery;
 }