Exemple #1
0
        public IRegistrationContainer Register(Type abstractType, Type concreteType,
                                               RegistrationLifeTime registrationLifeTime = RegistrationLifeTime.Transient, string key = null, bool shouldReplace = false)
        {
            _container.Register(abstractType, concreteType, registrationLifeTime.ToContainerLifeTime(), serviceKey: ResolveKey(key), ifAlreadyRegistered: Map(shouldReplace));

            return(this);
        }
Exemple #2
0
        public IRegistrationContainer Register(Type abstractType, Type concreteType,
                                               RegistrationLifeTime registrationLifeTime = RegistrationLifeTime.Transient, string key = null, bool shouldReplace = false)
        {
            _container.Register(abstractType, concreteType, registrationLifeTime.ToContainerLifeTime());

            return(this);
        }
Exemple #3
0
        public IRegistrationContainer RegisterFactory <TAbstract>(Func <IResolutionContainer, TAbstract> factoryFunc,
                                                                  RegistrationLifeTime registrationLifeTime = RegistrationLifeTime.Transient, string key = null, bool shouldReplace = false) where TAbstract : class

        {
            _container.RegisterDelegate(_ => factoryFunc(DryIocResolverAdapter.Adapt(_container)), registrationLifeTime.ToContainerLifeTime(), serviceKey: ResolveKey(key), ifAlreadyRegistered: Map(shouldReplace));
            return(this);
        }
Exemple #4
0
        public IRegistrationContainer Register(Type concreteType, RegistrationTarget target,
                                               RegistrationLifeTime registrationLifeTime = RegistrationLifeTime.Transient, string key = null, bool shouldReplace = false)
        {
            var serviceTypeCondition = TargetResolver.Resolve(target);

            _container.RegisterMany(new[] { concreteType }, registrationLifeTime.ToContainerLifeTime(), serviceTypeCondition: serviceTypeCondition, serviceKey: ResolveKey(key), ifAlreadyRegistered: Map(shouldReplace));
            return(this);
        }
Exemple #5
0
        public IRegistrationContainer Register <TAbstract, TConcrete>(
            RegistrationLifeTime registrationLifeTime = RegistrationLifeTime.Transient,
            Action <TAbstract> cleanupAction          = null,
            string key = null, bool shouldReplace = false) where TAbstract : class where TConcrete : class, TAbstract
        {
            _container.Register <TAbstract, TConcrete>(registrationLifeTime.ToContainerLifeTime());

            return(this);
        }
Exemple #6
0
        public IRegistrationContainer RegisterFactory <TAbstract>(Func <IResolutionContainer, TAbstract> factoryFunc,
                                                                  RegistrationLifeTime registrationLifeTime = RegistrationLifeTime.Transient, string key = null, bool shouldReplace = false) where TAbstract : class

        {
            SimpleInjectorIocResolverAdapter c = SimpleInjectorIocResolverAdapter.Adapt(_container);

            _container.Register <TAbstract>(() => factoryFunc(c), registrationLifeTime.ToContainerLifeTime());
            return(this);
        }
Exemple #7
0
        public IRegistrationContainer Register(Type concreteType, RegistrationTarget target,
                                               RegistrationLifeTime registrationLifeTime = RegistrationLifeTime.Transient, string key = null, bool shouldReplace = false)
        {
            var serviceTypeCondition = TargetResolver.Resolve(target);

            //_container.Register(concreteType);
            //_container.Register( concreteType.UnderlyingSystemType, () => concreteType, registrationLifeTime.ToContainerLifeTime());
            _container.Register(concreteType.GetType(), () => concreteType, registrationLifeTime.ToContainerLifeTime());
            return(this);
        }
Exemple #8
0
        public RegistrationInfo(RegistrationLifeTime lifeTime, string key = "")
        {
            if (!lifeTime.IsMemberOf <RegistrationLifeTime>())
            {
                throw new ArgumentOutOfRangeException(nameof(lifeTime));
            }
            LifeTime = lifeTime;

            HasKey = !string.IsNullOrWhiteSpace(key);

            Key = HasKey ? key : string.Empty;
        }
Exemple #9
0
        public IRegistrationContainer Register <TAbstract, TConcrete>(
            RegistrationLifeTime registrationLifeTime = RegistrationLifeTime.Transient,
            Action <TAbstract> cleanupAction          = null,
            string key = null, bool shouldReplace = false) where TAbstract : class where TConcrete : class, TAbstract
        {
            _container.Register <TAbstract, TConcrete>(registrationLifeTime.ToContainerLifeTime(), serviceKey: ResolveKey(key), ifAlreadyRegistered: Map(shouldReplace));

            if (cleanupAction != null)
            {
                _container.RegisterDisposer(cleanupAction);
            }

            return(this);
        }
Exemple #10
0
        public IRegistrationContainer RegisterDecorator(Type abstractType, Type decorator,
                                                        RegistrationLifeTime registrationLifeTime = RegistrationLifeTime.Transient, string key = null, bool shouldReplace = false)
        {
            var serviceKey = ResolveKey(key);

            if (string.IsNullOrEmpty(serviceKey))
            {
                _container.Register(abstractType, decorator, registrationLifeTime.ToContainerLifeTime(), setup: Setup.Decorator, ifAlreadyRegistered: Map(shouldReplace));
            }
            else
            {
                _container.Register(abstractType, decorator, registrationLifeTime.ToContainerLifeTime(), setup: Setup.DecoratorWith(r =>
                                                                                                                                    string.Equals(key, r.ServiceKey as string, StringComparison.OrdinalIgnoreCase)));
            }
            return(this);
        }
Exemple #11
0
        public static Lifestyle ToContainerLifeTime(this RegistrationLifeTime lifeTime)
        {
            switch (lifeTime)
            {
            case RegistrationLifeTime.Singleton:
                return(Lifestyle.Singleton);

            case RegistrationLifeTime.Transient:
                return(Lifestyle.Transient);

            case RegistrationLifeTime.ScopedOrSingleton:
                return(Lifestyle.Scoped);

            default:
                return(Lifestyle.Scoped);
            }
        }
Exemple #12
0
 public IRegistrationContainer RegisterDecorator(Type abstractType, Type decorator,
                                                 RegistrationLifeTime registrationLifeTime = RegistrationLifeTime.Transient, string key = null, bool shouldReplace = false)
 {
     throw new NotImplementedException();
 }
Exemple #13
0
 public IRegistrationContainer RegisterDecorator <TAbstract, TConcrete>(RegistrationLifeTime registrationLifeTime = RegistrationLifeTime.Transient, string key = null, bool shouldReplace = false) where TAbstract : class where TConcrete : class, TAbstract
 {
     throw new NotImplementedException();
 }
Exemple #14
0
 public IRegistrationContainer Register <TConcrete>(RegistrationTarget target, RegistrationLifeTime registrationLifeTime = RegistrationLifeTime.Transient, string key = null, bool shouldReplace = false)
 {
     return(Register(typeof(TConcrete), target, registrationLifeTime, key, shouldReplace));
 }
Exemple #15
0
 public IoCRegistrationAttribute(RegistrationLifeTime lifeTime, string key = "")
 {
     Information = new RegistrationInfo(lifeTime, key);
 }
Exemple #16
0
 public bool Matches(RegistrationLifeTime lifeTime)
 {
     return(lifeTime == LifeTime);
 }