/*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");
        }
        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");
        }
Ejemplo n.º 3
0
        private static ConfiguredInstance CreateExpression(this GenericFamilyExpression obj,
                                                           bool IsSingleton, Type concrete, string Name)
        {
            if (IsSingleton)
            {
                obj = obj.Singleton();
            }

            var res = obj.Use(concrete);

            if (!string.IsNullOrEmpty(Name))
            {
                res.Named(Name);
            }
            return(res);
        }