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)); }
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)); }
public IEnumerable <Expression> GetExpressionsForEnumerableRequest( IResolutionStrategy resolutionStrategy, TypeInformation typeInfo, ResolutionContext resolutionInfo) { return(new Expression[] { Expression.Constant(new Test1()) }); }
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; }
public bool TryGet(IResolutionStrategy resolutionStrategy, out object resolution) { if (_history.ContainsKey(resolutionStrategy)) { resolution = _history[resolutionStrategy]; return true; } resolution = null; return false; }
/// <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>(); }
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)); }
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; }
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); }
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()))); }
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)); }
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())); }
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); }
public IEnumerable <Expression> GetExpressionsForEnumerableRequest( IResolutionStrategy resolutionStrategy, TypeInformation typeInfo, ResolutionContext resolutionContext) => resolutionStrategy.BuildExpressionsForEnumerableRequest(resolutionContext.BeginCrossContainerContext(resolutionContext .CurrentContainerContext.ParentContext), typeInfo);
public Expression GetExpression( IResolutionStrategy resolutionStrategy, TypeInformation typeInfo, ResolutionContext resolutionContext) => resolutionStrategy.BuildExpressionForType(resolutionContext.BeginCrossContainerContext(resolutionContext .CurrentContainerContext.ParentContext), typeInfo);
public Expression GetExpression(IResolutionStrategy resolutionStrategy, TypeInformation typeInfo, ResolutionContext resolutionContext) => resolutionContext.CurrentScopeParameter;
public Expression GetExpression( IResolutionStrategy resolutionStrategy, TypeInformation typeInfo, ResolutionContext resolutionContext) => typeInfo.Type.AsDefault();
public Expression GetExpression(IResolutionStrategy resolutionStrategy, TypeInformation typeInfo, ResolutionContext resolutionInfo) { return(Expression.Constant(new Test1())); }
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); }
public Expression GetExpression( IResolutionStrategy resolutionStrategy, TypeInformation typeInfo, ResolutionContext resolutionContext) => typeInfo.DefaultValue.AsConstant(typeInfo.Type);
public CheckParentResolutionStrategyDecorator(IResolutionStrategy resolutionStrategy) { this.resolutionStrategy = resolutionStrategy; }
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);
public void TryPut(IResolutionStrategy resolutionStrategy, object resolution) { if (resolutionStrategy.Lifestyle == Lifestyle.Singleton) _history[resolutionStrategy] = resolution; }
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); }