private static IScopeContextInternal CreateConcreteType <T>(IScopeContextInternal context)
 {
     context =
         new ScopeContext(context.BoundType.MakeConcreteType(typeof(T).GetGenericArguments())).SetScope(
             context.ActivationScope.GetValueOrDefault(ScopeContext.GetDefaultScope()));
     return(context);
 }
 private static IScopeContextInternal CreateConcreteType(IScopeContextInternal context, Type serviceType)
 {
     context =
         new ScopeContext(context.BoundType.MakeConcreteType(serviceType.GetGenericArguments()), null).SetScope(
             context.ActivationScope.GetValueOrDefault(ScopeContext.GetDefaultScope()));
     return(context);
 }
        //private static object CreateInstance<T>(IScopeContextInternal context)
        //{
        //    if (context.BoundType.IsGenericTypeDefinition)
        //        context = CreateConcreteType(context, context.BoundType);
        //    return context.Activate();
        //}

        private static object CreateInstance(IScopeContextInternal context)
        {
            if (context.BoundType.IsGenericTypeDefinition)
            {
                context = CreateConcreteType(context, context.BoundType);
            }
            return(ActivatorFactory.Activator.Activate(context.BoundType));
        }
 private static Scope GetActivationScope(this IScopeContextInternal context, Scope?scope)
 {
     if ((context.AllowOverride || !context.ActivationScope.HasValue) && scope.HasValue)
     {
         return(scope.Value);
     }
     return(context.GetActivationScope());
 }
        private static object ActivateAndInitialize(IScopeContextInternal context, Action <object> initializeMethod)
        {
            var instance = (context.CreatorMethod.IsInstance() ? context.CreatorMethod() : CreateInstance(context));

            if (initializeMethod.IsInstance())
            {
                initializeMethod(instance);
            }
            return(instance);
        }
        private static T ActivateAndInitialize <T>(IScopeContextInternal context, Action <T> initializeMethod)
        {
            var instance = (T)(context.CreatorMethod.IsInstance() ? context.CreatorMethod(context.ActivationScopeContext?.Resolver) : CreateInstance(context));

            if (initializeMethod.IsInstance())
            {
                initializeMethod(instance);
            }
            return(instance);
        }
        internal static object Activate(this IScopeContextInternal context, Scope scope)
        {
            if (context.IsNull() || context.IsNull)
            {
                return(null);
            }

            var instance = ContainerFactory.Current.Resolve(context.BoundType, GetActivationScope(context, scope));

            if (!instance.IsNull())
            {
                return(instance);
            }
            instance = ActivateAndInitialize(context, null);
            ContainerFactory.Current.Bind(instance.GetType(), instance, GetActivationScope(context, scope));
            return(instance);
        }
        internal static T Activate <T>(this IScopeContextInternal context, Action <T> initializeMethod, Scope?scope = null)
        {
            if (context.IsNull() || context.IsNull)
            {
                return(default(T));
            }
            if (context.BoundType.IsGenericTypeDefinition)
            {
                context = CreateConcreteType <T>(context);
            }
            var instance = (T)ContainerFactory.Current.Resolve(context.BoundType, GetActivationScope(context, scope));

            if (!instance.IsNull())
            {
                return(instance);
            }
            instance = ActivateAndInitialize(context, initializeMethod);
            ContainerFactory.Current.Bind(instance.GetType(), instance, GetActivationScope(context, scope));
            return(instance);
        }
 internal static T Activate <T>(this IScopeContextInternal context, Scope scope, Action <T> initializeMethod)
 {
     return(context.Activate(initializeMethod, scope));
 }
 internal static T Activate <T>(this IScopeContextInternal context, Scope scope)
 {
     return(context.Activate <T>(null, GetActivationScope(context, scope)));
 }
 private static Scope GetActivationScope(this IScopeContextInternal context)
 {
     return(context.ActivationScope ?? Scope.PerRequest);
 }
Esempio n. 12
0
 internal ResolveContext(IScopeContextInternal typeContext)
 {
     TypeContext = typeContext;
 }
Esempio n. 13
0
 public InternalScopeContext(IScopeContextInternal typeContext, ContextProviders.IScopeContext scopeContext)
 {
     _typeContext           = typeContext;
     ActivationScopeContext = scopeContext;
 }
Esempio n. 14
0
 internal ResolveContext(IScopeContextInternal typeContext, ContextProviders.IScopeContext scopeContext)
 {
     Context     = scopeContext;
     TypeContext = new Internals.InternalScopeContext(typeContext, scopeContext);
 }