Esempio n. 1
0
        public bool RegisterService(LifeScopeTypeEnum lifeScope, Type type)
        {
            var regType       = ContainerBuilder.RegisterType(type);
            var haveInterface = false;

            if (AssemblyUtils.GetInterfaceOfType(type) != null)
            {
                regType       = regType.As(AssemblyUtils.GetInterfaceOfType(type));
                haveInterface = true;
            }

            switch (lifeScope)
            {
            case LifeScopeTypeEnum.SINGLETON:
                regType.SingleInstance();

                if (haveInterface)
                {
                    ContainerBuilder.RegisterType(type).SingleInstance();
                }
                break;

            case LifeScopeTypeEnum.SCOPED:
                regType.InstancePerLifetimeScope();
                if (haveInterface)
                {
                    ContainerBuilder.RegisterType(type).InstancePerLifetimeScope();
                }

                break;

            case LifeScopeTypeEnum.TRANSIENT:
                regType.InstancePerRequest();
                if (haveInterface)
                {
                    ContainerBuilder.RegisterType(type).InstancePerRequest();
                }

                break;
            }

            if (haveInterface)
            {
                _logger.LogDebug($"Registering type {type.Name} => {AssemblyUtils.GetInterfaceOfType(type).Name}");
            }
            else
            {
                _logger.LogDebug($"Registering type {type.Name}");
            }


            return(true);
        }
Esempio n. 2
0
 public bool RegisterService <T>(LifeScopeTypeEnum lifeScope)
 {
     return(RegisterService(lifeScope, typeof(T)));
 }