/// <summary> /// /// </summary> /// <param name="resolver"></param> /// <param name="parameterType"></param> /// <param name="setOperationExpression"></param> /// <returns></returns> public Expression CreateParameterExpression(IResolverPolicy resolver, Type parameterType, Expression setOperationExpression) { // The intent of this is to create a parameter resolving expression block. The following // pseudo code will hopefully make it clearer as to what we're trying to accomplish (of course actual code // trumps comments): // object priorOperation = context.CurrentOperation; // SetCurrentOperation // var resolver = GetResolver([context], [paramType], [key]) // var dependencyResult = resolver.ResolveDependency([context]); // context.CurrentOperation = priorOperation; // dependencyResult ; // return item from Block var savedOperationExpression = Expression.Parameter(typeof(object)); var resolvedObjectExpression = Expression.Parameter(parameterType); return (Expression.Block( new[] { savedOperationExpression, resolvedObjectExpression }, SaveCurrentOperationExpression(savedOperationExpression), setOperationExpression, Expression.Assign( resolvedObjectExpression, GetResolveDependencyExpression(parameterType, resolver)), RestoreCurrentOperationExpression(savedOperationExpression), resolvedObjectExpression)); }
private void AssertExpectedValue(InjectionParameter parameter, Type expectedType, object expectedValue) { IResolverPolicy resolver = parameter.GetResolverPolicy(expectedType); object result = resolver.Resolve(null); Assert.AreEqual(expectedType, parameter.ParameterType); AssertExtensions.IsInstanceOfType(resolver, typeof(LiteralValueDependencyResolverPolicy)); Assert.AreEqual(expectedValue, result); }
/// <summary> /// Return a <see cref="IResolverPolicy"/> that can be used to give a value /// for the given desired dependency. /// </summary> /// <param name="context">Current build context.</param> /// <param name="dependencyType">Type of dependency desired.</param> /// <returns>a <see cref="IResolverPolicy"/> object if this override applies, null if not.</returns> public override IResolverPolicy GetResolver(IBuilderContext context, Type dependencyType) { IResolverPolicy result = null; if (dependencyType == _typeToConstruct) { result = Value.GetResolverPolicy(dependencyType); } return(result); }
public void DependencyParameterCreatesExpectedResolver() { Type expectedType = typeof(ILogger); ResolvedParameter parameter = new ResolvedParameter <ILogger>(); IResolverPolicy resolver = parameter.GetResolverPolicy(expectedType); AssertExtensions.IsInstanceOfType(resolver, typeof(NamedTypeDependencyResolverPolicy)); Assert.AreEqual(expectedType, ((NamedTypeDependencyResolverPolicy)resolver).Type); Assert.IsNull(((NamedTypeDependencyResolverPolicy)resolver).Name); }
public void ObjectsConverterToInjectionParametersResolveCorrectly() { List <InjectionParameterValue> values = GetParameterValues(15); InjectionParameter parameter = (InjectionParameter)values[0]; Assert.AreEqual(typeof(int), parameter.ParameterType); IResolverPolicy policy = parameter.GetResolverPolicy(null); int result = (int)policy.Resolve(null); Assert.AreEqual(15, result); }
public void ResolvedParameterHandledNamedTypes() { Type expectedType = typeof(ILogger); string name = "special"; ResolvedParameter parameter = new ResolvedParameter(expectedType, name); IResolverPolicy resolver = parameter.GetResolverPolicy(expectedType); AssertExtensions.IsInstanceOfType(resolver, typeof(NamedTypeDependencyResolverPolicy)); Assert.AreEqual(expectedType, ((NamedTypeDependencyResolverPolicy)resolver).Type); Assert.AreEqual(name, ((NamedTypeDependencyResolverPolicy)resolver).Name); }
internal Expression GetResolveDependencyExpression(Type dependencyType, IResolverPolicy resolver) { return(Expression.Convert( Expression.Call( Expression.Call(null, GetResolverMethod, ContextParameter, Expression.Constant(dependencyType, typeof(Type)), Expression.Constant(resolver, typeof(IResolverPolicy))), ResolveDependencyMethod, ContextParameter), dependencyType)); }
private SelectedProperty CreateSelectedProperty(PropertyInfo property) { IResolverPolicy resolver = this.CreateResolver(property); return(new SelectedProperty(property, resolver)); }
/// <summary> /// Helper method used by generated IL to look up a dependency resolver based on the given key. /// </summary> /// <param name="context">Current build context.</param> /// <param name="dependencyType">Type of the dependency being resolved.</param> /// <param name="resolver">The configured resolver.</param> /// <returns>The found dependency resolver.</returns> public static IResolverPolicy GetResolver(IBuilderContext context, Type dependencyType, IResolverPolicy resolver) { var overridden = (context ?? throw new ArgumentNullException(nameof(context))).GetOverriddenResolver(dependencyType); return(overridden ?? resolver); }
private static void AssertPolicyIsCorrect(IResolverPolicy policy) { Assert.IsNotNull(policy); AssertExtensions.IsInstanceOfType(policy, typeof(LiteralValueDependencyResolverPolicy)); }
public InjectedObjectSelectorPolicy(IResolverPolicy resolverPolicy) { this.resolverPolicy = resolverPolicy; }
public InjectedObjectConfigurationExtension(IResolverPolicy resolverPolicy) { this.resolverPolicy = resolverPolicy; }
/// <summary> /// Adds the parameter resolver. Resolvers are assumed /// to be in the order of the parameters to the member. /// </summary> /// <param name="newResolver">The new resolver.</param> public void AddParameterResolver(IResolverPolicy newResolver) { _parameterResolvers.Add(newResolver); }
/// <summary> /// Create an instance of <see cref="SelectedProperty"/> /// with the given <see cref="PropertyInfo"/> and key. /// </summary> /// <param name="property">The property.</param> /// <param name="resolver"></param> public SelectedProperty(PropertyInfo property, IResolverPolicy resolver) { Property = property; Resolver = resolver; }