private static ComponentRegistration <T> SetLifeStyle <T>(LifeStyleType lifeStyle, ComponentRegistration <T> registration) where T : class
        {
            if (lifeStyle == LifeStyleType.Singleton)
            {
                return(registration.LifestyleSingleton());
            }
            else if (lifeStyle == LifeStyleType.Transient)
            {
                return(registration.LifestyleTransient());
            }
            else if (lifeStyle == LifeStyleType.PerWebRequest)
            {
                return(registration.LifestylePerWebRequest());
            }
            else if (lifeStyle == LifeStyleType.PerThread)
            {
                return(registration.LifestylePerThread());
            }
            else if (lifeStyle == LifeStyleType.Scoped)
            {
                return(registration.LifestyleScoped());
            }

            return(registration);
        }
예제 #2
0
        public void Register <TContract, TService>(LifeCycle lifeCycle, Func <TContract> factoryMethod = null)
            where TContract : class
            where TService : TContract
        {
            ComponentRegistration <TContract> component = Component.For <TContract>().ImplementedBy <TService>();

            switch (lifeCycle)
            {
            case LifeCycle.Transient:
                component = component.LifestyleTransient();
                break;

            case LifeCycle.Singletone:
                component = component.LifestyleSingleton();
                break;

            case LifeCycle.PerThread:
                component = component.LifestylePerThread();
                break;

            default:
                throw new NotSupportedException("Lifecycle");
            }

            if (factoryMethod != null)
            {
                component = component.UsingFactoryMethod(factoryMethod, managedExternally: true);
            }

            _Container.Register(component);
        }
예제 #3
0
        public static ComponentRegistration <T> SetLifeStyle <T>(this ComponentRegistration <T> registration, LifetimeScope lifeTimeKey) where T : class
        {
            switch (lifeTimeKey)
            {
            case LifetimeScope.Unowned:
                return(registration.LifestyleCustom <NoTrackLifestyleManager>());

            case LifetimeScope.Singleton:
                return(registration);

            case LifetimeScope.PerHttpRequest:
                return(registration.LifestylePerWebRequest());

            case LifetimeScope.PerThread:
                return(registration.LifestylePerThread());

            default:
                return(registration.LifestyleTransient());
            }
        }