コード例 #1
0
        public override IComponentRegistry Register(Type dependencyType, Type implementationType, Lifestyle lifestyle)
        {
            Guard.AgainstNull(dependencyType, "dependencyType");
            Guard.AgainstNull(implementationType, "implementationType");

            base.Register(dependencyType, implementationType, lifestyle);

            try
            {
                switch (lifestyle)
                {
                case Lifestyle.Transient:
                {
                    _container.Register(dependencyType, implementationType, global::SimpleInjector.Lifestyle.Transient);

                    break;
                }

                default:
                {
                    _container.Register(dependencyType, implementationType, global::SimpleInjector.Lifestyle.Singleton);

                    break;
                }
                }
            }
            catch (Exception ex)
            {
                throw new TypeRegistrationException(ex.Message, ex);
            }

            return(this);
        }
コード例 #2
0
        public override IComponentRegistry RegisterCollection(Type dependencyType, IEnumerable <Type> implementationTypes, Lifestyle lifestyle)
        {
            Guard.AgainstNull(dependencyType, "dependencyType");
            Guard.AgainstNull(implementationTypes, "implementationTypes");

            base.RegisterCollection(dependencyType, implementationTypes, lifestyle);

            try
            {
                switch (lifestyle)
                {
                case Lifestyle.Transient:
                {
                    _container.Collection.Register(dependencyType, implementationTypes.Select(t => global::SimpleInjector.Lifestyle.Transient.CreateRegistration(t, _container)));

                    break;
                }

                default:
                {
                    _container.Collection.Register(dependencyType, implementationTypes.Select(t => global::SimpleInjector.Lifestyle.Singleton.CreateRegistration(t, _container)));

                    break;
                }
                }
            }
            catch (Exception ex)
            {
                throw new TypeRegistrationException(ex.Message, ex);
            }

            return(this);
        }
コード例 #3
0
 public override IComponentRegistry RegisterGeneric(Type dependencyType, Type implementationType, Lifestyle lifestyle)
 {
     return(Register(dependencyType, implementationType, lifestyle));
 }