Ejemplo n.º 1
0
        /// <summary>
        /// 通过反射获取模块实例
        /// </summary>
        /// <param name="types"></param>
        private void CreateModules(List <Type> types)
        {
            //1:循环所有模块信息
            types.ForEach(type =>
            {
                //2:解析模块
                BaseModule instance = _iocManager.Resolve(type) as BaseModule;
                if (instance != null)
                {
                    instance.IocManager    = _iocManager;
                    instance.Configuration = _iocManager.Resolve <IBaseConfiguration>();
                    //3:初始化模块
                    ModuleInfo moduleInfo = new ModuleInfo(type, instance);

                    //4:递归查找模块的所有依赖
                    modules.Add(moduleInfo);
                    //5:检查该类型和启动类型是否一致,如果一致,那么设置启动模块
                    if (_startType == type)
                    {
                        StartModule = moduleInfo;
                    }

                    Logger.DebugFormat("module:{0} is loaded", type.FullName);
                }
            });
        }
Ejemplo n.º 2
0
        private void CreateModules(ICollection <Type> moduleTypes)
        {
            foreach (var moduleType in moduleTypes)
            {
                var moduleObject = _iocManager.Resolve(moduleType) as BaseModule;
                if (moduleObject == null)
                {
                    throw new ZSharpInitializationException("This type is not an ZSharp module: " + moduleType.AssemblyQualifiedName);
                }

                moduleObject.IocManager    = _iocManager;
                moduleObject.Configuration = _iocManager.Resolve <IStartupConfiguration>();

                var moduleInfo = new ModuleInfo(moduleType, moduleObject);

                _modules.Add(moduleInfo);

                if (moduleType == _startupModuleType)
                {
                    StartupModule = moduleInfo;
                }

                Logger.DebugFormat("Loaded module: " + moduleType.AssemblyQualifiedName);
            }
        }
Ejemplo n.º 3
0
        public AbpNHibernateInterceptor(IIocManager iocManager)
        {
            _iocManager = iocManager;

            _abpSession =
                new Lazy <IAbpSession>(
                    () => _iocManager.IsRegistered(typeof(IAbpSession))
                        ? _iocManager.Resolve <IAbpSession>()
                        : NullAbpSession.Instance,
                    isThreadSafe: true
                    );
            _guidGenerator =
                new Lazy <IGuidGenerator>(
                    () => _iocManager.IsRegistered(typeof(IGuidGenerator))
                        ? _iocManager.Resolve <IGuidGenerator>()
                        : SequentialGuidGenerator.Instance,
                    isThreadSafe: true
                    );

            _eventBus =
                new Lazy <IEventBus>(
                    () => _iocManager.IsRegistered(typeof(IEventBus))
                        ? _iocManager.Resolve <IEventBus>()
                        : NullEventBus.Instance,
                    isThreadSafe: true
                    );
        }
        public AbpNHibernateInterceptor(IIocManager iocManager)
        {
            _iocManager = iocManager;

            _abpSession =
                new Lazy<IAbpSession>(
                    () => _iocManager.IsRegistered(typeof(IAbpSession))
                        ? _iocManager.Resolve<IAbpSession>()
                        : NullAbpSession.Instance,
                    isThreadSafe: true
                    );
            _guidGenerator =
                new Lazy<IGuidGenerator>(
                    () => _iocManager.IsRegistered(typeof(IGuidGenerator))
                        ? _iocManager.Resolve<IGuidGenerator>()
                        : SequentialGuidGenerator.Instance,
                    isThreadSafe: true
                    );

            _eventBus =
                new Lazy<IEventBus>(
                    () => _iocManager.IsRegistered(typeof(IEventBus))
                        ? _iocManager.Resolve<IEventBus>()
                        : NullEventBus.Instance,
                    isThreadSafe: true
                );
        }
Ejemplo n.º 5
0
        public SheshaNHibernateInterceptor(IIocManager iocManager)
        {
            try
            {
                _iocManager = iocManager;

                _abpSession =
                    new Lazy <IAbpSession>(
                        () => _iocManager.IsRegistered(typeof(IAbpSession))
                            ? _iocManager.Resolve <IAbpSession>()
                            : NullAbpSession.Instance,
                        isThreadSafe: true
                        );
                _guidGenerator =
                    new Lazy <IGuidGenerator>(
                        () => _iocManager.IsRegistered(typeof(IGuidGenerator))
                            ? _iocManager.Resolve <IGuidGenerator>()
                            : SequentialGuidGenerator.Instance,
                        isThreadSafe: true
                        );

                _eventBus =
                    new Lazy <IEventBus>(
                        () => _iocManager.IsRegistered(typeof(IEventBus))
                            ? _iocManager.Resolve <IEventBus>()
                            : NullEventBus.Instance,
                        isThreadSafe: true
                        );
            }
            catch (Exception e)
            {
                Logger.Error(e.Message, e);
            }
        }
Ejemplo n.º 6
0
        private void CreateModules(ICollection <Type> moduleTypes, List <Type> plugInModuleTypes)
        {
            foreach (var moduleType in moduleTypes)
            {
                var moduleObject = _iocManager.Resolve(moduleType) as AbpModule;
                if (moduleObject == null)
                {
                    throw new AbpInitializationException("This type is not an ABP module: " + moduleType.AssemblyQualifiedName);
                }

                moduleObject.IocManager    = _iocManager;
                moduleObject.Configuration = _iocManager.Resolve <IAbpStartupConfiguration>();

                var moduleInfo = new AbpModuleInfo(moduleType, moduleObject, plugInModuleTypes.Contains(moduleType));

                _modules.Add(moduleInfo);

                if (moduleType == _modules.StartupModuleType)
                {
                    StartupModule = moduleInfo;
                }

                Logger.DebugFormat("Loaded module: " + moduleType.AssemblyQualifiedName);
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Initializes the complete system.
        /// </summary>
        public virtual void Initialize()
        {
            _iocManager.IocContainer.Install(new AbpCoreInstaller());

            _iocManager.Resolve <AbpStartupConfiguration>().Initialize();

            _moduleManager = _iocManager.Resolve <IAbpModuleManager>();
            _moduleManager.InitializeModules();
        }
        public static void Initialize(IIocManager iocManager)
        {
            using (var unitOfQWork = iocManager.Resolve <Abp.Domain.Uow.IUnitOfWorkManager>().Begin(TransactionScopeOption.RequiresNew))
            {
                var repository       = iocManager.Resolve <IRepository <DataItem, Guid> >();
                var enumerationTypes =
                    iocManager.Resolve <ITypeFinder>().Find(type =>
                                                            type.IsPublic &&
                                                            !type.IsAbstract &&
                                                            type.IsClass &&
                                                            typeof(Enumeration).IsAssignableFrom(type)
                                                            );
                foreach (var enumerationType in enumerationTypes)
                {
                    var enumerationStatics = enumerationType.GetFields(BindingFlags.Static | BindingFlags.Public);
                    if (enumerationStatics.Length == 0)
                    {
                        continue;
                    }

                    var enumeration = (Enumeration)enumerationStatics[0].GetValue(null);
                    var dataItem    = repository.FirstOrDefault(s => s.ItemCode == enumeration.Category);
                    if (dataItem == null)
                    {
                        dataItem = new DataItem()
                        {
                            ItemCode        = enumeration.Category,
                            ItemName        = GetDescriptionName(enumerationType) ?? enumeration.Category,
                            Creator         = Guid.Parse(UserBase.SYSTEM_USERID),
                            DataItemDetails = new List <DataitemDetail>(),
                            AllowDelete     = false,
                            AllowEdit       = false,
                        };
                    }
                    foreach (var enumerationStatic in enumerationStatics)
                    {
                        var filed = (Enumeration)enumerationStatic.GetValue(null);
                        if (!dataItem.DataItemDetails.Any(s => s.ItemCode == filed.Key))
                        {
                            dataItem.DataItemDetails.Add(new DataitemDetail()
                            {
                                IsDefault   = true,
                                ItemCode    = filed.Key,
                                ItemValue   = filed.Value,
                                Creator     = Guid.Parse(UserBase.SYSTEM_USERID),
                                AllowDelete = false,
                                AllowEdit   = false,
                            });
                        }
                    }
                    repository.InsertOrUpdate(dataItem);
                }
                unitOfQWork.Complete();
            }
        }
Ejemplo n.º 9
0
        private void LoadAll()
        {
            Logger.Debug("Loading Abp modules...");

            var moduleTypes = AddMissingDependedModules(_moduleFinder.FindAll());

            Logger.Debug("Found " + moduleTypes.Count + " ABP modules in total.");

            //Register to IOC container.
            foreach (var moduleType in moduleTypes)
            {
                if (!AbpModule.IsAbpModule(moduleType))
                {
                    throw new AbpInitializationException("This type is not an ABP module: " + moduleType.AssemblyQualifiedName);
                }

                if (!_iocManager.IsRegistered(moduleType))
                {
                    _iocManager.Register(moduleType);
                }
            }

            //Add to module collection
            foreach (var moduleType in moduleTypes)
            {
                var moduleObject = (AbpModule)_iocManager.Resolve(moduleType);

                moduleObject.IocManager    = _iocManager;
                moduleObject.Configuration = _iocManager.Resolve <IAbpStartupConfiguration>();

                _modules.Add(new AbpModuleInfo(moduleObject));

                Logger.DebugFormat("Loaded module: " + moduleType.AssemblyQualifiedName);
            }

            //AbpKernelModule must be the first module
            //var startupModuleIndex = _modules.FindIndex(m => m.Type == typeof(AbpKernelModule<TTenantId, TUserId>));
            //var startupModuleIndex = _modules.FindIndex(m => m.Type == typeof(AbpKernelModule<,>));
            var startupModuleIndex = _modules.FindIndex(m => m.Type == typeof(AbpKernelModule));

            if (startupModuleIndex > 0)
            {
                var startupModule = _modules[startupModuleIndex];
                _modules.RemoveAt(startupModuleIndex);
                _modules.Insert(0, startupModule);
            }

            SetDependencies();

            Logger.DebugFormat("{0} modules loaded.", _modules.Count);
        }
Ejemplo n.º 10
0
        public void TestMethod1()
        {
            _iocManager.IocContainer.Register(Component.For <ITaskService>().ImplementedBy <TaskService>().LifestyleSingleton());
            ITaskService taskService = _iocManager.Resolve <ITaskService>();

            Assert.AreEqual("aa", taskService.SaveTask("aa"));
        }
Ejemplo n.º 11
0
        public BdfNHibernateInterceptor(IIocManager iocManager)
        {
            _iocManager = iocManager;
             _BdfSession =
                new Lazy<IBdfSession>(
                    () => _iocManager.IsRegistered(typeof(IBdfSession))
                        ? _iocManager.Resolve<IBdfSession>()
                        : NullBdfSession.Instance
                    );

            EntityChangedEventHelper =
                _iocManager.IsRegistered(typeof (IEntityChangedEventHelper))
                    ? _iocManager.Resolve<IEntityChangedEventHelper>()
                    : NullEntityChangedEventHelper.Instance;
        }
Ejemplo n.º 12
0
        public BdfNHibernateInterceptor(IIocManager iocManager)
        {
            _iocManager = iocManager;
            _BdfSession =
                new Lazy <IBdfSession>(
                    () => _iocManager.IsRegistered(typeof(IBdfSession))
                        ? _iocManager.Resolve <IBdfSession>()
                        : NullBdfSession.Instance
                    );

            EntityChangedEventHelper =
                _iocManager.IsRegistered(typeof(IEntityChangedEventHelper))
                    ? _iocManager.Resolve <IEntityChangedEventHelper>()
                    : NullEntityChangedEventHelper.Instance;
        }
Ejemplo n.º 13
0
        public void Configure()
        {
            IIocManager      iocManager = IocManager.Instance;
            IAppInfoProvider appInfo    = iocManager.Resolve <IAppInfoProvider>();
            ILogger          logger     = iocManager.Resolve <ILogger <AfterRunConfigureModule> >();
            IEnumerable <IAfterRunConfigure> configures = iocManager.Resolve <IEnumerable <IAfterRunConfigure> >();

            Task.Factory.StartNew(() =>
            {
                tsdnHttpRequest request = new tsdnHttpRequest();
                string name             = SysConfig.MicroServiceOption.Application.Name;
                request.AddressUrl      = $"http://{appInfo.IpAddress}:{appInfo.Ports[0]}/api/{name}/Health/ApiServer";
                int i = 0;
                while (true)
                {
                    try
                    {
                        var responeMessage = request.SendAsync().Result;
                        if (responeMessage.StatusCode == HttpStatusCode.OK)
                        {
                            if (configures != null && configures.Count() > 0)
                            {
                                foreach (var item in configures.OrderBy(e => e.Order))
                                {
                                    try
                                    {
                                        item.Configure();
                                    }
                                    catch (Exception e)
                                    {
                                        logger.LogError(e.InnerException != null ? e.InnerException : e, $"调用类型{item.GetType().ToString()}的Configure方法异常");
                                    }
                                }
                            }
                            break;
                        }
                    }
                    catch { }
                    if (i > 30)
                    {
                        logger.LogError("程序启动异常,30s内http服务还未启动成功");
                        break;
                    }
                    i++;
                    Task.Delay(100).Wait();
                }
            });
        }
Ejemplo n.º 14
0
        /// <summary>
        ///
        /// </summary>
        public void Configure()
        {
            MicroRegisterInfo info = new MicroRegisterInfo();

            info.app   = GetAppInfo();
            info.hosts = GetHostInfo();
            info.paths = GetApiInfo();

            string          url     = SysConfig.MicroServiceOption.Cloud.RegistCenterUri + "/micro/UDDI/Register";
            tsdnHttpRequest request = new tsdnHttpRequest();

            request.AddressUrl = url;
            request.Method     = HttpMethod.Post;
            request.Body       = info;
            bool result = request.SendAsync <bool>().Result;

            if (result)
            {
                logger.LogInformation($"向注册中心({SysConfig.MicroServiceOption.Cloud.RegistCenterUri})注册节点成功");
                if (SysConfig.MicroServiceOption.Type == RegisterType.IMS)
                {
                    var menuRegister = iocManager.Resolve <IMenuRegister>(RegisterType.IMS.ToString());
                    menuRegister.RegisterMenu();
                }
            }
        }
Ejemplo n.º 15
0
        private static bool ShouldIntercept(IIocManager iocManager, Type type)
        {
            if (type.GetTypeInfo().IsDefined(typeof(AuditedAttribute), true))
            {
                return(true);
            }

            if (type.GetMethods().Any(m => m.IsDefined(typeof(AuditedAttribute), true)))
            {
                return(true);
            }

            if (!iocManager.IsRegistered <IAbpAuditingDefaultOptions>())
            {
                return(false);
            }

            var auditingOptions = iocManager.Resolve <IAbpAuditingDefaultOptions>();

            if (auditingOptions.ConventionalAuditingSelectors.Any(selector => selector(type)))
            {
                return(true);
            }

            return(false);
        }
Ejemplo n.º 16
0
        public void Install(IIocManager iocManager)
        {
            if (_eventBusConfiguration.UseDefaultEventBus)
            {
                iocManager.IocContainer.UseInstance <IEventBus>(EventBus.Default);
            }
            else
            {
                iocManager.IocContainer.Register <IEventBus, EventBus>(Reuse.Singleton);
            }

            _eventBus = iocManager.Resolve <IEventBus>();
            iocManager.RegisterTypeEventHandler += (manager, type, implementationType) =>
            {
                if (!typeof(IEventHandler).GetTypeInfo().IsAssignableFrom(implementationType))
                {
                    return;
                }

                var interfaces = implementationType.GetTypeInfo().GetInterfaces();
                foreach (var @interface in interfaces)
                {
                    if (!typeof(IEventHandler).GetTypeInfo().IsAssignableFrom(@interface))
                    {
                        continue;
                    }

                    var genericArgs = @interface.GetGenericArguments();
                    if (genericArgs.Length == 1)
                    {
                        _eventBus.Register(genericArgs[0], new IocHandlerFactory(_iocResolver, implementationType));
                    }
                }
            };
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Initializes the registerer.
        /// </summary>
        /// <param name="iocManager">IOC manager</param>
        public static void Initialize(IIocManager iocManager)
        {
            iocManager.IocContainer.Kernel.ComponentRegistered += (key, handler) =>
            {
                if (!iocManager.IsRegistered <IUnitOfWorkDefaultOptions>())
                {
                    return;
                }

                var uowOptions = iocManager.Resolve <IUnitOfWorkDefaultOptions>();

                if (uowOptions.IsConventionalUowClass(handler.ComponentModel.Implementation))
                {
                    handler.ComponentModel.Interceptors.Add(new InterceptorReference(typeof(UnitOfWorkInterceptor)));
                }
                else if (UnitOfWorkHelper.HasUnitOfWorkAttribute(handler.ComponentModel.Implementation.GetTypeInfo()) ||
                         handler.ComponentModel
                         .Implementation
                         .GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
                         .Any(UnitOfWorkHelper.HasUnitOfWorkAttribute))
                {
                    //Intercept all methods of classes those have at least one method that has UnitOfWork attribute or class marked as UnitOfWork.
                    handler.ComponentModel.Interceptors.Add(new InterceptorReference(typeof(UnitOfWorkInterceptor)));
                }
            };
        }
Ejemplo n.º 18
0
        /// <summary>
        /// 加载所有组件。
        /// </summary>
        private void LoadAllComponents()
        {
            ICollection <Type> componentTypes = AddMissingDependedComponents(_componentFinder.FindAll());

            foreach (Type componentType in componentTypes)
            {
                if (!ComponentBase.IsComponent(componentType))
                {
                    throw new Exception(string.Format("{0} 不是 Ls 组件。", componentType.AssemblyQualifiedName));
                }

                if (!_iocManager.IsRegistered(componentType))
                {
                    _iocManager.Register(componentType);
                }
            }

            foreach (Type componentType in componentTypes)
            {
                ComponentBase componentObject = (ComponentBase)_iocManager.Resolve(componentType);
                componentObject.IocManager = _iocManager;
                _components.Add(new ComponentDescription(componentObject));
            }

            int coreComponentIndex = _components.FindIndex(m => m.Type == typeof(LsCoreComponent));

            if (coreComponentIndex > 0)
            {
                ComponentDescription coreComponent = _components[coreComponentIndex];
                _components.RemoveAt(coreComponentIndex);
                _components.Insert(0, coreComponent);
            }

            SetDependencies();
        }
Ejemplo n.º 19
0
 public HozaruNHibernateInterceptor(IIocManager iocManager)
 {
     _iocManager    = iocManager;
     _hozaruSession =
         new Lazy <IHozaruSession>(
             () => _iocManager.IsRegistered(typeof(IHozaruSession))
                 ? _iocManager.Resolve <IHozaruSession>()
                 : NullHozaruSession.Instance
             );
     _guidGenerator =
         new Lazy <IGuidGenerator>(
             () => _iocManager.IsRegistered(typeof(IGuidGenerator))
                 ? _iocManager.Resolve <IGuidGenerator>()
                 : SequentialGuidGenerator.Instance
             );
 }
Ejemplo n.º 20
0
        static TResult Forward <TResult>(ControllerContext controllerContext, IIocManager iIocManager,
                                         Func <IThemeAwareViewEngine, TResult> forwardAction, Func <TResult> defaultAction)
        {
//            var workContext = controllerContext.GetWorkContext();
//            if (workContext != null)
//            {
//                var displayViewEngine = workContext.Resolve<IThemeAwareViewEngine>();
//                if (displayViewEngine != null)
//                {
//                    return forwardAction(displayViewEngine);
//                }
//            }
            Stopwatch sw = Stopwatch.StartNew();

            if (iIocManager != null)
            {
                var displayViewEngine = iIocManager.Resolve <IThemeAwareViewEngine>();
                if (displayViewEngine != null)
                {
                    var fa = forwardAction(displayViewEngine);
                    sw.Stop();
                    LogHelper.logger.Debug($"ThemeAwareViewEngineShim cost time {sw.ElapsedMilliseconds}ms");
                    return(fa);
                }
            }

            return(defaultAction());
        }
        // 因为拦截器只能拦截虚方法与接口方法.
        public virtual string InterceptorTest()
        {
            // 因为在一个请求范围之内,所以这里 scopeObject 的 Guid 值应该与 GetScopedObject 当中解析的值一样。
            var scopeObject = _iocManager.Resolve <ScopeClass>();

            return("Ok");
        }
Ejemplo n.º 22
0
        public HubReadWriterResultModel DoWork(HubReadWriterModel hubRead)
        {
            Type   handlerType = default;
            object handler     = default;

            try
            {
                handlerType = Type.GetType($"MMK.SmartSystem.CNC.Core.DeviceInOut.{hubRead.ProxyName}");
                handler     = iocManager.Resolve(handlerType);
                var connMethod = handlerType.GetMethod("BuildConnect");
                var connRes    = (bool)connMethod.Invoke(handler, null);
                if (!connRes)
                {
                    return(new HubReadWriterResultModel()
                    {
                        Action = hubRead.Action,
                        ConnectId = hubRead.ConnectId,
                        Error = "CNC建立连接失败",
                        ProxyName = hubRead.ProxyName,
                        Result = new object(),
                        Success = false,
                        Id = hubRead.Id
                    });
                }
                var methodInfo = handlerType.GetMethod(hubRead.Action);
                var res        = methodInfo.Invoke(handler, new object[] { hubRead }) as HubReadWriterResultModel ?? new HubReadWriterResultModel();
                res.Action    = hubRead.Action;
                res.ConnectId = hubRead.ConnectId;
                res.Id        = hubRead.Id;
                res.ProxyName = hubRead.ProxyName;
                return(res);
            }
            catch (Exception ex)
            {
                return(new HubReadWriterResultModel()
                {
                    Action = hubRead.Action,
                    ConnectId = hubRead.ConnectId,
                    Error = ex.Message + ex.InnerException?.Message,
                    ProxyName = hubRead.ProxyName,
                    Result = new object(),
                    Success = false,
                    Id = hubRead.Id
                });
            }
            finally
            {
                var closeConnect = handlerType.GetMethod("CloseConnect");
                if (closeConnect != null && handler != null)
                {
                    try
                    {
                        closeConnect.Invoke(handler, null);
                    }
                    catch (Exception)
                    {
                    }
                }
            }
        }
Ejemplo n.º 23
0
        private static void Test_Way_1(IIocManager iocManager)
        {
            var tester = iocManager.Resolve <Tester>();

            tester.Test();

            iocManager.Release(tester);
        }
Ejemplo n.º 24
0
 /// <summary>
 /// 获取当前上下文的工作单元,若不存在,则创建新的。
 /// </summary>
 /// <returns>返回当前上下文的工作单元。</returns>
 public IUnitOfWork NewUnitOfWork()
 {
     if (UnitOfWorkCreator.UnitOfWork == null)
     {
         UnitOfWorkCreator.UnitOfWork = _iocManager.Resolve <IUnitOfWork>();
     }
     return(UnitOfWorkCreator.UnitOfWork);
 }
Ejemplo n.º 25
0
 protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType)
 {
     if (controllerType == null)
     {
         return(null);
     }
     return((IController)_iocManager.Resolve(controllerType));
 }
Ejemplo n.º 26
0
        private static void Test_Way_1(IIocManager iocManager)
        {
            var tester = iocManager.Resolve<Tester>();

            tester.Test();

            iocManager.Release(tester);
        }
Ejemplo n.º 27
0
        private AuthorizationProvider CreateAuthorizationProvider(Type providerType)
        {
            if (!_iocManager.IsRegistered(providerType))
            {
                _iocManager.Register(providerType);
            }

            return((AuthorizationProvider)_iocManager.Resolve(providerType));
        }
        private SettingProvider CreateProvider(Type providerType)
        {
            if (!_iocManager.IsRegistered(providerType))
            {
                _iocManager.Register(providerType);
            }

            return((SettingProvider)_iocManager.Resolve(providerType));
        }
        /// <summary>
        /// 创建控制器对象
        /// </summary>
        /// <param name="requestContext"></param>
        /// <param name="controllerType"></param>
        /// <returns></returns>
        protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType)
        {
            if (null == controllerType)
            {
                return(null);
            }

            return(_iocManger.Resolve(controllerType) as IController);
        }
 public AbpNHibernateInterceptor(IIocManager iocManager)
 {
     _iocManager = iocManager;
     _abpSession =
         new Lazy<IAbpSession>(
             () => _iocManager.IsRegistered(typeof(IAbpSession))
                 ? _iocManager.Resolve<IAbpSession>()
                 : NullAbpSession.Instance
             );
 }
        public void MultObjectUseSameInterfaceDefaultFirst()
        {
            IConventionalDependencyRegistrar register = new MultObjectConventionalRegistrar();

            register.RegisterAssembly(new Blocks.Framework.Ioc.Dependency.ConventionalRegistrationContext(this.GetType().Assembly, _iocManager, null));

            var actualObject = _iocManager.Resolve <ILog>();

            Assert.True(actualObject is Log4Net);
        }
Ejemplo n.º 32
0
        public void Configure()
        {
            IIocManager      iocManager = IocManager.Instance;
            IAppInfoProvider appInfo    = iocManager.Resolve <IAppInfoProvider>();
            ILogger          logger     = iocManager.Resolve <ILogger <AfterRunConfigureModule> >();
            IEnumerable <IAfterRunConfigure> configures = iocManager.Resolve <IEnumerable <IAfterRunConfigure> >();

            if (configures == null && configures.Count() == 0)
            {
                return;
            }

            Task.Factory.StartNew(() =>
            {
                int i = 0;
                while (!HostHelper.IsPortInUsed(Convert.ToInt32(appInfo.Ports[0])))
                {
                    try
                    {
                        foreach (var item in configures.OrderBy(e => e.Order))
                        {
                            try
                            {
                                item.Configure();
                            }
                            catch (Exception e)
                            {
                                logger.LogError(e.InnerException != null ? e.InnerException : e, $"调用类型{item.GetType().ToString()}的Configure方法异常");
                            }
                        }
                        break;
                    }
                    catch { }
                    if (i > 30)
                    {
                        logger.LogError("程序启动异常,30s内http服务还未启动成功");
                        break;
                    }
                    i++;
                    Task.Delay(100).Wait();
                }
            });
        }
Ejemplo n.º 33
0
        //public Task<bool> IsGrantedAsync(IUserIdentifier user, string permission)
        //{
        //    return Task.FromResult(true);
        //}



        public Task <bool> IsGrantedAsync(IUserIdentifier user, Permission permission)
        {
            Task <bool> result = Task.FromResult(true);

            if (_iocManager.IsRegistered <IPermissionCheck>())
            {
                result = _iocManager.Resolve <IPermissionCheck>().IsGrantedAsync(user, permission);
            }
            return(result);
        }
Ejemplo n.º 34
0
 public AbpNHibernateInterceptor(IIocManager iocManager)
 {
     _iocManager = iocManager;
     _abpSession =
         new Lazy <IAbpSession>(
             () => _iocManager.IsRegistered(typeof(IAbpSession))
                 ? _iocManager.Resolve <IAbpSession>()
                 : NullAbpSession.Instance
             );
 }
        public static void Initialize(IIocManager iocManager)
        {
            _auditingConfiguration = iocManager.Resolve<IAuditingConfiguration>();

            if (!_auditingConfiguration.IsEnabled)
            {
                return;
            }

            iocManager.IocContainer.Kernel.ComponentRegistered += Kernel_ComponentRegistered;
        }
 public static void Initialize(IIocManager iocManager)
 {
     var auditingConfiguration = iocManager.Resolve<IAuditingConfiguration>();
     iocManager.IocContainer.Kernel.ComponentRegistered += (key, handler) =>
     {
         if (ShouldIntercept(auditingConfiguration, handler.ComponentModel.Implementation))
         {
             handler.ComponentModel.Interceptors.Add(new InterceptorReference(typeof(AuditingInterceptor)));
         }
     };
 }
 public AuditingInterceptorRegistrar(IIocManager iocManager)
 {
     _iocManager = iocManager;
     _auditingConfiguration = _iocManager.Resolve<IAuditingConfiguration>();
 }
Ejemplo n.º 38
0
 public EventInitializer()
 {
     _iocManager = IocManager.Instance;
     _eventHandlerFinder = _iocManager.Resolve<IEventHandlerFinder>();
 }