/*private static ConfiguredInstance ApplyResolver(GenericFamilyExpression builder, StaticResolver resolver)
         *      {
         *              return builder.Add(resolver.Target);
         *      }
         *
         *      private static ObjectInstance ApplyResolver(GenericFamilyExpression builder, InstanceResolver resolver)
         *      {
         *              return builder.Add(resolver.Instance);
         *      }
         *
         *      private static LambdaInstance<object> ApplyResolver(GenericFamilyExpression builder, DynamicResolver resolver)
         *      {
         *              return builder.Add(c => resolver.FactoryFunc());
         *      }*/

        private static GenericFamilyExpression ApplyLifestyleSingle(GenericFamilyExpression registration, Lifestyle lifestyle)
        {
            if (lifestyle.Name == Lifestyle.Singleton.Name)
            {
                return(registration.Singleton());
            }

            if (lifestyle.Name == Lifestyle.Transient.Name)
            {
                return(registration.LifecycleIs(new TransientLifecycle()));
            }

            if (lifestyle.Name == Lifestyle.PerWebRequest.Name)
            {
                return(registration.LifecycleIs(new UniquePerRequestLifecycle()));
            }

            if (lifestyle.Name == Lifestyle.Unmanaged.Name)
            {
                return(registration);
            }

            if (lifestyle.Name == Lifestyle.ProviderDefault.Name)
            {
                return(registration);
            }

            if (lifestyle.Name == Lifestyle.Default.Name)
            {
                return(registration.Singleton());
            }

            throw new ArgumentException(string.Format("Unknown lifestyle : {0}", lifestyle), "lifestyle");
        }
예제 #2
0
        private GenericFamilyExpression SetLifetime(GenericFamilyExpression e)
        {
            switch (LifetimeForRegisters)
            {
            case ServiceRegistrarLifetime.Transient: return(e);    // e.LifecycleIs(InstanceScope.Transient);

            case ServiceRegistrarLifetime.Singleton: return(e.LifecycleIs(InstanceScope.Singleton));

            case ServiceRegistrarLifetime.Thread: return(e.LifecycleIs(InstanceScope.ThreadLocal));

            case ServiceRegistrarLifetime.Request: return(e.LifecycleIs(InstanceScope.PerRequest));

            default: throw new NotSupportedException();
            }
        }
        public static GenericFamilyExpression LifecycleIs(this GenericFamilyExpression instance, ServiceLifetime lifetime)
        {
            switch (lifetime)
            {
            case ServiceLifetime.Singleton:
                return(instance.LifecycleIs(Lifecycles.Singleton));

            case ServiceLifetime.Scoped:
                return(instance.LifecycleIs(Lifecycles.Container));

            case ServiceLifetime.Transient:
                return(instance.LifecycleIs(Lifecycles.Unique));

            default:
                throw new ArgumentOutOfRangeException(nameof(lifetime), lifetime, null);
            }
        }
        private static GenericFamilyExpression ApplyLifestyleSingle(GenericFamilyExpression registration, Lifestyle lifestyle)
        {
            if (lifestyle.Name == Lifestyle.Singleton.Name)
                return registration.Singleton();

            if (lifestyle.Name == Lifestyle.Transient.Name)
                return registration.LifecycleIs(InstanceScope.PerRequest);

            if (lifestyle.Name == Lifestyle.PerWebRequest.Name)
                return registration.HttpContextScoped();

            if (lifestyle.Name == Lifestyle.Unmanaged.Name)
                return registration;

            if (lifestyle.Name == Lifestyle.ProviderDefault.Name)
                return registration;

            if (lifestyle.Name == Lifestyle.Default.Name)
                return registration.Singleton();

            throw new ArgumentException(string.Format("Unknown lifestyle : {0}", lifestyle), "lifestyle");
        }
 /// <summary>
 /// Convenience method to mark a PluginFamily as HttpContext scoped
 /// </summary>
 /// <returns></returns>
 public static GenericFamilyExpression HttpContextScoped(this GenericFamilyExpression expression)
 {
     return(expression.LifecycleIs(WebLifecycles.HttpContext));
 }
 /// <summary>
 /// Convenience method to mark a PluginFamily as a Hybrid lifecycle
 /// </summary>
 /// <returns></returns>
 public static GenericFamilyExpression HybridHttpOrThreadLocalScoped(this GenericFamilyExpression expression)
 {
     return(expression.LifecycleIs(WebLifecycles.Hybrid));
 }
예제 #7
0
 public static GenericFamilyExpression WithNoLifecycle(this GenericFamilyExpression expression)
 {
     expression.LifecycleIs(new NoLifecycle());
     return(expression);
 }