예제 #1
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);
        }
예제 #2
0
 static EventBroker()
 {
     Instance = new EventBroker();
 }