Exemple #1
0
 /// <summary>
 /// 扫描并注册AOP容器
 /// </summary>
 /// <param name="config"></param>
 internal static void RegisterAopContainer(CFConfig config)
 {
     config.ScanAttributes <IocAttribute>((type, attribute) =>
     {
         CFAspect.RegisterType(attribute.RegisterType, type, CFAspect.GetLifetimeManager(attribute.LifetimeManagerType), CFAspect.GetInjectionMembers(attribute.AopType, attribute.RegisterType));
     });
 }
        /// <summary>
        /// 扫描并注册Ioc容器
        /// </summary>
        /// <param name="config"></param>
        internal static void RegisterIocContainer(CFConfig config)
        {
            var currentType = typeof(ApplicationModule);
            var containers  = new List <ApplicationModule>();

            //查找程序集中CFAspect的子类
            config.ScanTypes(type =>
            {
                if (type.IsSubclassOf(currentType))
                {
                    dynamic ct = Activator.CreateInstance(type);
                    containers.Add(ct);
                }
            });
            //模块初始化
            foreach (var ct in containers)
            {
                try
                {
                    ct.Init();
                }
                catch
                {
                    continue;
                }
            }
            //模块启动
            foreach (var ct in containers)
            {
                try
                {
                    ct.Load();
                }
                catch
                {
                    continue;
                }
            }
        }