예제 #1
0
        public Expression GetExpression(
            IResolutionStrategy resolutionStrategy,
            TypeInformation typeInfo,
            ResolutionContext resolutionContext)
        {
            var args             = typeInfo.Type.GetGenericArguments();
            var tupleConstructor = typeInfo.Type.GetConstructor(args);
            var length           = args.Length;
            var expressions      = new Expression[length];

            for (var i = 0; i < length; i++)
            {
                var argumentInfo = typeInfo.CloneForType(args[i]);
                var expr         = resolutionStrategy.BuildExpressionForType(resolutionContext, argumentInfo);

                if (expr != null)
                {
                    expressions[i] = expr;
                }
                else
                {
                    return(null);
                }
            }

            return(tupleConstructor.MakeNew(expressions));
        }
예제 #2
0
        public Expression GetExpression(
            IResolutionStrategy resolutionStrategy,
            TypeInformation typeInfo,
            ResolutionContext resolutionContext)
        {
            var name         = typeInfo.DependencyName;
            var configurator = name != null
                ? context =>
            {
                context.WithName(name);
                resolutionContext.RequestInitiatorContainerContext.ContainerConfiguration.UnknownTypeConfigurator?.Invoke(context);
            }
            : resolutionContext.RequestInitiatorContainerContext.ContainerConfiguration.UnknownTypeConfigurator;

            var registrationConfigurator = new UnknownRegistrationConfigurator(typeInfo.Type, typeInfo.Type);

            configurator?.Invoke(registrationConfigurator);

            if (!registrationConfigurator.TypeMapIsValid(out _))
            {
                return(null);
            }

            var registration = this.registrationBuilder.BuildServiceRegistration(resolutionContext.RequestInitiatorContainerContext,
                                                                                 registrationConfigurator, false);

            this.serviceRegistrator.Register(resolutionContext.RequestInitiatorContainerContext, registration, typeInfo.Type);

            return(resolutionStrategy.BuildExpressionForRegistration(registration, resolutionContext.ShouldFallBackToRequestInitiatorContext
                ? resolutionContext.BeginCrossContainerContext(resolutionContext.RequestInitiatorContainerContext)
                : resolutionContext,
                                                                     typeInfo));
        }
예제 #3
0
 public IEnumerable <Expression> GetExpressionsForEnumerableRequest(
     IResolutionStrategy resolutionStrategy,
     TypeInformation typeInfo,
     ResolutionContext resolutionInfo)
 {
     return(new Expression[] { Expression.Constant(new Test1()) });
 }
예제 #4
0
 internal ContainerContext(IRegistrationRepository registrationRepository, IStashboxContainer container,
                           IResolutionStrategy resolutionStrategy, IContainerConfigurator containerConfigurator, IDecoratorRepository decoratorRepository)
 {
     this.ResolutionStrategy     = resolutionStrategy;
     this.RegistrationRepository = registrationRepository;
     this.Container             = container;
     this.ContainerConfigurator = containerConfigurator;
     this.DecoratorRepository   = decoratorRepository;
 }
예제 #5
0
 public bool TryGet(IResolutionStrategy resolutionStrategy, out object resolution)
 {
     if (_history.ContainsKey(resolutionStrategy))
     {
         resolution = _history[resolutionStrategy];
         return true;
     }
     resolution = null;
     return false;
 }
예제 #6
0
 /// <summary>
 /// Constructs a <see cref="ContainerContext"/>
 /// </summary>
 /// <param name="registrationRepository">The repository of the registrations.</param>
 /// <param name="container">The container itself.</param>
 /// <param name="resolutionStrategy">The resolution strategy.</param>
 /// <param name="metaInfoRepository">The meta information repository.</param>
 /// <param name="delegateRepository">Repository of the compiled delegates.</param>
 internal ContainerContext(IRegistrationRepository registrationRepository, IStashboxContainer container,
     IResolutionStrategy resolutionStrategy, ExtendedImmutableTree<MetaInfoCache> metaInfoRepository,
     ExtendedImmutableTree<Func<ResolutionInfo, object>> delegateRepository)
 {
     this.RegistrationRepository = registrationRepository;
     this.Container = container;
     this.ResolutionStrategy = resolutionStrategy;
     this.MetaInfoRepository = metaInfoRepository;
     this.DelegateRepository = delegateRepository;
     this.Bag = new ConcurrentKeyValueStore<object, object>();
 }
예제 #7
0
        public Expression GetExpression(
            IResolutionStrategy resolutionStrategy,
            TypeInformation typeInfo,
            ResolutionContext resolutionContext)
        {
            var newTypeInfo = typeInfo.CloneForType(typeInfo.Type.GetEnumerableType());
            var expressions = resolutionStrategy.BuildExpressionsForEnumerableRequest(resolutionContext, newTypeInfo);

            return(expressions == null?newTypeInfo.Type.InitNewArray() :
                       newTypeInfo.Type.InitNewArray(expressions));
        }
예제 #8
0
 internal ContainerContext(IRegistrationRepository registrationRepository, IDelegateRepository delegateRepository,
                           IStashboxContainer container, IResolutionStrategy resolutionStrategy, IContainerConfigurator containerConfigurator,
                           IDecoratorRepository decoratorRepository)
 {
     this.ResolutionStrategy     = resolutionStrategy;
     this.RegistrationRepository = registrationRepository;
     this.DelegateRepository     = delegateRepository;
     this.Container             = container;
     this.Bag                   = new ConcurrentKeyValueStore <object, object>();
     this.ContainerConfigurator = containerConfigurator;
     this.DecoratorRepository   = decoratorRepository;
 }
예제 #9
0
        public DnsResolver(
            IOptionsMonitor <ResolverOptions> options,
            IResolutionStrategy resolutionStrategy,
            IDnsMsgBinSerializer dnsSerializer)
        {
            this.options            = options ?? throw new ArgumentNullException(nameof(options));
            this.resolutionStrategy = resolutionStrategy ?? throw new ArgumentNullException(nameof(resolutionStrategy));
            this.dnsSerializer      = dnsSerializer ?? throw new ArgumentNullException(nameof(dnsSerializer));

            this.listenPort = (ushort)options.CurrentValue.ListenPort;
            this.listener   = new UdpListener(ProcessRawQuery, this.listenPort);
        }
예제 #10
0
        public IEnumerable <Expression> GetExpressionsForEnumerableRequest(
            IResolutionStrategy resolutionStrategy,
            TypeInformation typeInfo,
            ResolutionContext resolutionContext)
        {
            var lazyArgumentInfo = typeInfo.CloneForType(typeInfo.Type.GetGenericArguments()[0]);

            var ctorParamType   = Constants.FuncType.MakeGenericType(lazyArgumentInfo.Type);
            var lazyConstructor = typeInfo.Type.GetConstructor(ctorParamType);

            return(resolutionStrategy.BuildExpressionsForEnumerableRequest(resolutionContext, lazyArgumentInfo)
                   ?.Select(e => lazyConstructor.MakeNew(e.AsLambda())));
        }
예제 #11
0
        public Expression GetExpression(IResolutionStrategy resolutionStrategy, TypeInformation typeInfo,
                                        ResolutionContext resolutionContext)
        {
            var args             = typeInfo.Type.GetGenericArguments();
            var wrappedType      = args.LastElement();
            var funcArgumentInfo = typeInfo.CloneForType(wrappedType);

            var parameters = args.SelectButLast(a => a.AsParameter());
            var expression = resolutionStrategy.BuildExpressionForType(resolutionContext
                                                                       .BeginContextWithFunctionParameters(parameters), funcArgumentInfo);

            return(expression?.AsLambda(typeInfo.Type, parameters));
        }
예제 #12
0
        public Expression GetExpression(
            IResolutionStrategy resolutionStrategy,
            TypeInformation typeInfo,
            ResolutionContext resolutionContext)
        {
            var lazyArgumentInfo = typeInfo.CloneForType(typeInfo.Type.GetGenericArguments()[0]);

            var ctorParamType   = Constants.FuncType.MakeGenericType(lazyArgumentInfo.Type);
            var lazyConstructor = typeInfo.Type.GetConstructor(ctorParamType);
            var expression      = this.GetLazyFuncExpression(lazyArgumentInfo, resolutionContext, resolutionStrategy);

            return(expression == null ? null : lazyConstructor.MakeNew(expression.AsLambda()));
        }
예제 #13
0
        public IEnumerable <Expression> GetExpressionsForEnumerableRequest(IResolutionStrategy resolutionStrategy, TypeInformation typeInfo,
                                                                           ResolutionContext resolutionContext)
        {
            var type             = typeInfo.Type;
            var args             = type.GetGenericArguments();
            var wrappedType      = args.LastElement();
            var funcArgumentInfo = typeInfo.CloneForType(wrappedType);

            var parameters = args.SelectButLast(a => a.AsParameter());

            return(resolutionStrategy.BuildExpressionsForEnumerableRequest(resolutionContext
                                                                           .BeginContextWithFunctionParameters(parameters), funcArgumentInfo)?
                   .Select(e => e.AsLambda(type, parameters)));
        }
        private DependencyResolutionOptions SetResolutionStrategy(Type contractType, IResolutionStrategy resolutionStrategy)
        {
            object constructedObject;

            if (this.resolutionStrategies.ContainsKey(contractType))
            {
                if (this.resolutionStrategies[contractType].Equals(resolutionStrategy))
                {
                    return(this.resolutionOptions[contractType]);
                }
            }

            if (this.locallyCreatedDependencies.TryGetValue(contractType, out constructedObject) || this.injectedDependencies.TryGetValue(contractType, out constructedObject))
            {
                this.InvalidateConstructedObjects(constructedObject);
            }

            this.resolutionStrategies[contractType] = resolutionStrategy;
            var options = new DependencyResolutionOptions();

            this.resolutionOptions[contractType] = options;
            return(options);
        }
예제 #15
0
 public IEnumerable <Expression> GetExpressionsForEnumerableRequest(
     IResolutionStrategy resolutionStrategy,
     TypeInformation typeInfo,
     ResolutionContext resolutionContext) =>
 resolutionStrategy.BuildExpressionsForEnumerableRequest(resolutionContext.BeginCrossContainerContext(resolutionContext
                                                                                                      .CurrentContainerContext.ParentContext), typeInfo);
예제 #16
0
 public Expression GetExpression(
     IResolutionStrategy resolutionStrategy,
     TypeInformation typeInfo,
     ResolutionContext resolutionContext) =>
 resolutionStrategy.BuildExpressionForType(resolutionContext.BeginCrossContainerContext(resolutionContext
                                                                                        .CurrentContainerContext.ParentContext), typeInfo);
예제 #17
0
 public Expression GetExpression(IResolutionStrategy resolutionStrategy, TypeInformation typeInfo,
                                 ResolutionContext resolutionContext) => resolutionContext.CurrentScopeParameter;
예제 #18
0
 public Expression GetExpression(
     IResolutionStrategy resolutionStrategy,
     TypeInformation typeInfo,
     ResolutionContext resolutionContext) =>
 typeInfo.Type.AsDefault();
예제 #19
0
 public Expression GetExpression(IResolutionStrategy resolutionStrategy,
                                 TypeInformation typeInfo,
                                 ResolutionContext resolutionInfo)
 {
     return(Expression.Constant(new Test1()));
 }
예제 #20
0
        public static Expression BuildResolutionExpression(this ImmutableBucket <IResolver> resolvers,
                                                           TypeInformation typeInfo, ResolutionContext resolutionContext, IResolutionStrategy resolutionStrategy)
        {
            var length = resolvers.Length;

            for (var i = 0; i < length; i++)
            {
                var item = resolvers[i];
                if (item.CanUseForResolution(typeInfo, resolutionContext))
                {
                    return(item.GetExpression(resolutionStrategy, typeInfo, resolutionContext));
                }
            }

            return(null);
        }
예제 #21
0
 public Expression GetExpression(
     IResolutionStrategy resolutionStrategy,
     TypeInformation typeInfo,
     ResolutionContext resolutionContext) =>
 typeInfo.DefaultValue.AsConstant(typeInfo.Type);
예제 #22
0
 public CheckParentResolutionStrategyDecorator(IResolutionStrategy resolutionStrategy)
 {
     this.resolutionStrategy = resolutionStrategy;
 }
예제 #23
0
 private Expression GetLazyFuncExpression(TypeInformation argumentType,
                                          ResolutionContext resolutionContext, IResolutionStrategy resolutionStrategy) =>
 resolutionContext.CurrentContainerContext.ContainerConfiguration.CircularDependenciesWithLazyEnabled
         ? resolutionContext.CurrentScopeParameter
 .CallMethod(Constants.ResolveMethod, argumentType.Type.AsConstant(),
             argumentType.DependencyName.AsConstant(), false.AsConstant(),
             Constants.ObjectType.InitNewArray(resolutionContext.ParameterExpressions
                                               .SelectMany(x => x.Select(i => i.I2.ConvertTo(Constants.ObjectType)))))
 .ConvertTo(argumentType.Type)
         : resolutionStrategy.BuildExpressionForType(resolutionContext, argumentType);
예제 #24
0
 public void TryPut(IResolutionStrategy resolutionStrategy, object resolution)
 {
     if (resolutionStrategy.Lifestyle == Lifestyle.Singleton) _history[resolutionStrategy] = resolution;
 }
예제 #25
0
        public static IEnumerable <Expression> BuildAllResolutionExpressions(this ImmutableBucket <IResolver> resolvers,
                                                                             TypeInformation typeInfo, ResolutionContext resolutionContext, IResolutionStrategy resolutionStrategy)
        {
            var length = resolvers.Length;

            for (var i = 0; i < length; i++)
            {
                var item = resolvers[i];
                if (item is IEnumerableSupportedResolver resolver && item.CanUseForResolution(typeInfo, resolutionContext))
                {
                    return(resolver.GetExpressionsForEnumerableRequest(resolutionStrategy, typeInfo, resolutionContext));
                }
            }

            return(null);
        }