示例#1
0
        private static ComponentRegistration <object> ConfigureLifecycle(this ComponentRegistration <object> registrationBuilder, ServiceLifetime serviceLifetime)
        {
            switch (serviceLifetime)
            {
            case ServiceLifetime.Transient:
                registrationBuilder.LifestyleCustom <MsScopedTransientLifestyleManager>();
                break;

            case ServiceLifetime.Scoped:
                registrationBuilder.LifestyleCustom <MsScopedLifestyleManager>();
                break;

            case ServiceLifetime.Singleton:
                registrationBuilder.LifestyleCustom <MyScopedSingletonLifestyleManager>();
                break;

            default:
                throw new NotImplementedException("Unknown ServiceLifetime: " + serviceLifetime);
            }

            return(registrationBuilder);
        }
        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());
            }
        }