Example #1
0
 protected virtual string[] GetComponentConfigurations(BaseConfig configuration)
 {
     var configurations = new List<string>();
     var trustConfiguration = (this.GetTrustLevel() > AspNetHostingPermissionLevel.Medium)
         ? ConfigurationKeys.FullTrust
         : ConfigurationKeys.MediumTrust;
     configurations.Add(trustConfiguration);
     return configurations.ToArray();
 }
Example #2
0
        /// <summary>
        /// 创建一个配置节点
        /// </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 BaseConfig();
            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;
            }

            return config;
        }
Example #3
0
        /// <summary>
        /// 执行配置
        /// </summary>
        /// <param name="engine"></param>
        /// <param name="containerManager"></param>
        /// <param name="broker"></param>
        /// <param name="configuration"></param>
        public virtual void Configure(IEngine engine, ContainerManager containerManager, EventBroker broker, BaseConfig configuration)
        {
            //基础组件
            //添加基础配置的实例
            containerManager.AddComponentInstance<BaseConfig>(configuration, "Platform.Configuration");
            //添加引擎的实现
            containerManager.AddComponentInstance<IEngine>(engine, "Platform.Engine");
            //添加组件容器配置服务的实例
            containerManager.AddComponentInstance<ContainerConfigurer>(this, "Platform.ContainerConfigurer");
            //添加类型查找器服务的实现
            containerManager.AddComponent<ITypeFinder, WebAppTypeFinder>("Platform.TypeFinder");

            //注册的其他组件提供的依赖
            var typeFinder = containerManager.Resolve<ITypeFinder>();
            containerManager.UpdateContainer(x => {
                var drTypes = typeFinder.FindClassesOfType<IDependencyRegistrar>();
                var drInstances = new List<IDependencyRegistrar>();
                foreach (var drType in drTypes)
                {
                    drInstances.Add((IDependencyRegistrar)Activator.CreateInstance(drType));
                }
                //排序
                drInstances = drInstances.AsQueryable().OrderBy(t => t.Order).ToList();
                foreach (var dependencyRegistrar in drInstances)
                {
                    dependencyRegistrar.Register(x, typeFinder);
                }
            });

            //事件代理
            containerManager.AddComponentInstance(broker);

            //添加通过特性配置的依赖关系
            containerManager.AddComponent<DependencyAttributeRegistrator>("Platform.DependencyRegistrator");
            var registrator = containerManager.Resolve<DependencyAttributeRegistrator>();
            var services = registrator.FindServices();
            var configurations = this.GetComponentConfigurations(configuration);
            services = registrator.FilterServices(services, configurations);
            registrator.RegisterServices(services);
        }
Example #4
0
 public WebAppTypeFinder(BaseConfig config)
 {
     this._ensureBinFolderAssembliesLoaded = config.DynamicDiscovery;
 }