object InstantiateBinding(IActivationStrategy strategy, Type type) => strategy switch
 {
Ejemplo n.º 2
0
 public override IActivationOptions <TSource> DoBinding(IActivationStrategy strategy)
 {
     return(registry.Bind <TSource>(sources, strategy, ifNeeded));
 }
Ejemplo n.º 3
0
 public override IActivationOptions <TSource> DoBinding(IActivationStrategy strategy) =>
 Registry.Bind <TSource>(targetType, strategy, IfNeeded);
Ejemplo n.º 4
0
 public ObjectFactory(IActivationStrategy innerActivationStrategy, IInterceptionRule interceptionRule) :
     base(innerActivationStrategy)
 {
     this.interceptionRule = interceptionRule;
 }
Ejemplo n.º 5
0
            /// <summary>
            /// Default constructor
            /// </summary>
            /// <param name="scope"></param>
            /// <param name="request"></param>
            /// <param name="injectionContextCreator"></param>
            /// <param name="activationStrategy"></param>
            public DelegateExpression(IInjectionScope scope, IActivationExpressionRequest request,
                                      IInjectionContextCreator injectionContextCreator, IActivationStrategy activationStrategy)
            {
                _injectionContextCreator = injectionContextCreator;

                var newRequest = request.NewRequest(typeof(TResult), activationStrategy, typeof(TDelegate), RequestType.Other, null, true);

                newRequest.AddKnownValueExpression(CreateKnownValueExpression(request, typeof(TArg1), _arg1Id));

                newRequest.SetLocateKey(request.LocateKey);
                newRequest.DisposalScopeExpression = request.Constants.RootDisposalScope;

                var activationExpression = request.Services.ExpressionBuilder.GetActivationExpression(scope, newRequest);

                _action = request.Services.Compiler.CompileDelegate(scope, activationExpression);

                _funcMethodInfo = typeof(FuncClass).GetTypeInfo().GetDeclaredMethod(nameof(FuncClass.Func));
            }
 public AddParametersStrategy(IActivationStrategy innerActivationStrategy, object[] parameters) : base(innerActivationStrategy)
 {
     this.parameters = parameters;
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Default constructor
 /// </summary>
 /// <param name="scope"></param>
 /// <param name="request"></param>
 /// <param name="activationStrategy"></param>
 public LazyExpression(IInjectionScope scope, IActivationExpressionRequest request, IActivationStrategy activationStrategy)
 {
     _scope              = scope;
     _request            = request;
     _activationStrategy = activationStrategy;
 }
Ejemplo n.º 8
0
 public InterceptorStrategy(IActivationStrategy activationStrategy, IInterceptor[] interceptors) :
     base(activationStrategy) =>
     this.interceptors = interceptors;
Ejemplo n.º 9
0
 /// <summary>
 /// Default constructor
 /// </summary>
 /// <param name="request"></param>
 /// <param name="activationStrategy"></param>
 public LocateExpressionReplacer(IActivationExpressionRequest request, IActivationStrategy activationStrategy)
 {
     _request            = request;
     _activationStrategy = activationStrategy;
 }
 public MultipleActivationStrategy(IActivationStrategy strategy) => strateies.Add(strategy);
Ejemplo n.º 11
0
 public TypeInterceptorStrategy(IActivationStrategy activationStrategy) :
     base(activationStrategy)
 {
 }
Ejemplo n.º 12
0
        /// <summary>
        /// Test if being injected into a specific type
        /// </summary>
        /// <param name="strategy">strategy to test</param>
        /// <param name="staticInjectionContext">static injection context</param>
        /// <returns></returns>
        public bool MeetsCondition(IActivationStrategy strategy, StaticInjectionContext staticInjectionContext)
        {
            var targetInfo = staticInjectionContext.TargetInfo;

            return(targetInfo?.InjectionType != null && _typeTest(targetInfo.InjectionType));
        }
 public ForwardingActivationStrategy(IActivationStrategy innerActivationStrategy)
 {
     this.InnerActivationStrategy = innerActivationStrategy;
 }
 /// <summary>
 /// Default constructor
 /// </summary>
 /// <param name="activationType"></param>
 /// <param name="activationStrategy"></param>
 public TypeActivationConfiguration(Type activationType, IActivationStrategy activationStrategy)
 {
     ActivationType     = activationType;
     ActivationStrategy = activationStrategy;
     SupportsDecorators = false;
 }
 public WrappingActivationStrategy(IActivationStrategy parent,
                                   Func <T, IBindingRequest, T> wrapperFunc) : base(parent)
 {
     this.wrapperFunc = wrapperFunc;
 }
Ejemplo n.º 16
0
 public bool TryGetValue(IActivationStrategy source, [NotNullWhen(true)] out object?value) =>
 scopeItems.TryGetValue(source, out value) ||
 ((ParentScope as IScope)?.TryGetValue(source, out value) ?? false);
 public LambdaCondition(IActivationStrategy inner, Func <IBindingRequest, bool> shouldAllowBinding) : base(inner)
 {
     this.shouldAllowBinding = shouldAllowBinding;
 }
Ejemplo n.º 18
0
 public void SetScopeValue(IActivationStrategy source, object?value) => scopeItems.Add(source, value);
Ejemplo n.º 19
0
 public AttemptDisposeRegistration(IActivationStrategy innerActivationStrategy) : base(innerActivationStrategy)
 {
 }
 public ForbidDisposalStrategy(IActivationStrategy inner, bool forbidDisposeEvenIfInScope) : base(inner)
 {
     this.forbidDisposeEvenIfInScope = forbidDisposeEvenIfInScope;
 }
Ejemplo n.º 21
0
        /// <summary>
        /// Create an expression to call delegate and apply null check and disposal logic
        /// </summary>
        /// <param name="delegateInstance"></param>
        /// <param name="allowDisposableTracking"></param>
        /// <param name="scope"></param>
        /// <param name="request"></param>
        /// <param name="requestingStrategy"></param>
        /// <returns></returns>
        public static IActivationExpressionResult CreateExpressionForDelegate(Delegate delegateInstance, bool allowDisposableTracking, IInjectionScope scope,
                                                                              IActivationExpressionRequest request, IActivationStrategy requestingStrategy)
        {
            var methodInfo = delegateInstance.GetMethodInfo();

            Expression expression = null;

            IActivationExpressionResult[] resultsExpressions;

            // Handle closure based delegates differently
            if (delegateInstance.Target != null && delegateInstance.Target.GetType().FullName == _closureName)
            {
                resultsExpressions = CreateExpressionsForTypes(requestingStrategy, scope, request, methodInfo.ReturnType,
                                                               methodInfo.GetParameters().
                                                               Where(p => !(p.Position == 0 && p.ParameterType.FullName == "System.Runtime.CompilerServices.Closure")).
                                                               Select(p => p.ParameterType).ToArray());

                expression = Expression.Invoke(Expression.Constant(delegateInstance),
                                               resultsExpressions.Select(e => e.Expression));
            }
            else
            {
                resultsExpressions = CreateExpressionsForTypes(requestingStrategy, scope, request, methodInfo.ReturnType,
                                                               methodInfo.GetParameters().Select(p => p.ParameterType).ToArray());

                expression = methodInfo.IsStatic
                    ? Expression.Call(methodInfo, resultsExpressions.Select(e => e.Expression))
                    : Expression.Call(Expression.Constant(delegateInstance.Target),
                                      methodInfo, resultsExpressions.Select(e => e.Expression));
            }

            var allowNull = (requestingStrategy as IInstanceActivationStrategy)?.AllowNullReturn ?? false;

            expression = ApplyNullCheckAndAddDisposal(scope, request, expression, allowDisposableTracking, allowNull);

            var result = request.Services.Compiler.CreateNewResult(request, expression);

            foreach (var expressionResult in resultsExpressions)
            {
                result.AddExpressionResult(expressionResult);
            }

            return(result);
        }
Ejemplo n.º 22
0
 /// <summary>
 /// Test if condition is meet
 /// </summary>
 /// <param name="strategy">strategy to test</param>
 /// <param name="staticInjectionContext">static injection context</param>
 /// <returns>true if condition is meet</returns>
 public bool MeetsCondition(IActivationStrategy strategy, StaticInjectionContext staticInjectionContext)
 {
     return(_condition(strategy, staticInjectionContext));
 }
 /// <summary>
 /// Default constructor
 /// </summary>
 /// <param name="scope"></param>
 /// <param name="request"></param>
 /// <param name="activationStrategy"></param>
 /// <param name="metadata"></param>
 public LazyExpression(IInjectionScope scope, IActivationExpressionRequest request, IActivationStrategy activationStrategy, TMetadata metadata)
 {
     _scope              = scope;
     _request            = request;
     _activationStrategy = activationStrategy;
     _metadata           = metadata;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="Binding"/> class.
 /// </summary>
 /// <param name="service"><see cref="Type"/> of service.</param>
 /// <param name="strategy"><see cref="IActivationStrategy"/> for the service.</param>
 /// <param name="scope"><see cref="IScope"/> for the service.</param>
 public Binding(Type service, IActivationStrategy strategy, IScope scope)
 {
     Service  = service;
     Strategy = strategy;
     Scope    = scope;
 }
Ejemplo n.º 25
0
            /// <summary>
            /// Default constructor
            /// </summary>
            /// <param name="scope"></param>
            /// <param name="request"></param>
            /// <param name="activationStrategy"></param>
            public FuncExpression(IInjectionScope scope, IActivationExpressionRequest request, IActivationStrategy activationStrategy)
            {
                var requestType = request.ActivationType.GenericTypeArguments[0];

                var newRequest = request.NewRequest(requestType, activationStrategy, typeof(Func <TResult>), RequestType.Other, null, true);

                newRequest.DisposalScopeExpression = request.Constants.RootDisposalScope;

                var activationExpression = request.Services.ExpressionBuilder.GetActivationExpression(scope, newRequest);

                _action = request.Services.Compiler.CompileDelegate(scope, activationExpression);
            }
 public static IActivationStrategy EnsureSingleton(IActivationStrategy inner) =>
 inner.SharingScope() == IocContainers.SharingScope.Singleton
         ? inner
         : new SingletonActivationStrategy(inner);