/// <summary> /// Initializes a new instance of the DependencyMapLoader class. /// </summary> /// <param name="constructorResolver"></param> /// <param name="typeLoader">The type loader that will load the service types from each assembly.</param> /// <param name="serviceLoader">The service loader that will load services from a given assembly.</param> /// <param name="defaultServiceResolver">The resolver that will determine the default anonymous implementation for a particular service type.</param> public DependencyMapLoader(IConstructorResolver constructorResolver, ITypeLoader typeLoader, IServiceLoader serviceLoader, IDefaultServiceResolver defaultServiceResolver) { _constructorResolver = constructorResolver; _typeLoader = typeLoader; _serviceLoader = serviceLoader; _defaultServiceResolver = defaultServiceResolver; }
private void RemoveProcessedMembers(IConstructorResolver resolver) { foreach (var ctor in resolver.GetProcessedConstructors()) { foreach (var parameter in ctor.Key.GetParameters()) { MemberExpression key = null; foreach (var r in _resolution.Keys) { if (r.Member.Name.Equals(parameter.Name, StringComparison.OrdinalIgnoreCase) && r.Type == parameter.ParameterType && ctor.Key.DeclaringType == r.Member.DeclaringType) { key = r; break; } } if (key != null) { _resolution.Remove(key); } } } }
public Expression GetConstructor(IConstructorResolver constructorResolver) { var ctor = constructorResolver.Resolve(InputParameter, OutputParameter); if (ctor == null) { throw new InvalidOperationException($"It was not possible determine a constructor to the type [{Output.FullName}]."); } RemoveProcessedMembers(constructorResolver); return(ctor); }
/// <summary> /// Initializes a new instance of the TransientType class. /// </summary> /// <param name="targetType">The target type.</param> /// <param name="container">The dependency container.</param> /// <param name="resolver">The constructor resolver.</param> public TransientType(System.Type targetType, IDependencyContainer container, IConstructorResolver resolver) { _targetType = targetType; _container = container; _resolver = resolver; _getConstructorImplementation = () => { var result = _resolver.ResolveFrom(targetType, _container); if (result == null) { var message = string.Format("Unable to find a constructor for target type '{0}'", targetType.AssemblyQualifiedName); throw new ConstructorNotFoundException(message); } return(result); }; }
/// <summary> /// Initializes a new instance of the <see cref="DependencyMap"/> class. /// </summary> /// <param name="constructorResolver">The resolver that will be used to determine the constructor that will be used to instantiate a given object instance.</param> /// <param name="compiler">The compiler that will be used to compile this map into an IOC container.</param> public DependencyMap(IConstructorResolver constructorResolver, IContainerCompiler compiler) { if (compiler == null) { throw new ArgumentNullException("compiler"); } if (constructorResolver == null) { throw new ArgumentNullException("constructorResolver"); } _constructorResolver = constructorResolver; ContainerCompiler = compiler; // Allow the container to introduce itself to the types that it instantiates var dependency = new Dependency(typeof(IMicroContainer)); AddService(dependency, new ContainerInstanceCall()); }
/// <summary> /// Wraps around the passed <paramref name="constructorResolver"></paramref> to add caching. /// </summary> /// <param name="constructorResolver"></param> public ConstructorResolverCache(IConstructorResolver constructorResolver) { _constructorResolver = constructorResolver; }
/// <summary> /// Initializes a new instance of the <see cref="GeometryConstructor"/> class. /// </summary> /// <param name="resolver">The resolver of object constructors for particular constructions.</param> public GeometryConstructor(IConstructorResolver resolver) { _resolver = resolver ?? throw new ArgumentNullException(nameof(resolver)); }
/// <summary> /// Initializes a new instance of the DependencyMapLoader class. /// </summary> public DependencyMapLoader(IConstructorResolver constructorResolver) : this(constructorResolver, new TypeLoader(), new ServiceLoader(), new DefaultServiceResolver()) { }
public static Expression?ResolveConstructorExpression(this IConstructorResolver resolver, Type type) { return(resolver.ResolveConstructorExpression(type, resolver.StaticSelectConstructor(type))); }
public ConstructorResolverTests() { container = new Mock <IContainer>(); constructorResolver = new ConstructorResolver(container.Object); }
public static IMethodCompiler <TDelegate> ResolveConstructorTo <[DelegateConstraint] TDelegate>(this ConstructorInfo ctor, IConstructorResolver constructorInfoResolver) where TDelegate : class { return(ResolveConstructorTo <TDelegate>(constructorInfoResolver)); }
/// <summary> /// Returns the expression to call the constructor that is selected by <paramref name="resolver"/> for the passed <paramref name="type"/> /// </summary> /// <param name="resolver"></param> /// <param name="type"></param> /// <returns></returns> public static Expression ResolveConstructorExpression(this IConstructorResolver resolver, Type type) { return(TryResolveConstructorExpression(resolver, type) ?? throw new ArgumentException(nameof(type), $"Could not resolve {type} with {resolver}")); }
/// <summary> /// Initializes a new instance of the <see cref="ComposedConstructor"/> class. /// </summary> /// <param name="construction">The composed construction performed by the constructor.</param> /// <param name="constructionResolver">The resolver of constructors used while constructing the internal configuration of the composed construction.</param> /// <param name="tracer">The tracer for unexpected analytic exceptions.</param> public ComposedConstructor(ComposedConstruction construction, IConstructorResolver constructionResolver, IConstructorFailureTracer tracer) : base(tracer) { _construction = construction ?? throw new ArgumentNullException(nameof(construction)); _constructionResolver = constructionResolver ?? throw new ArgumentNullException(nameof(constructionResolver)); }
/// <summary> /// Initializes a new instance of the SingletonType class. /// </summary> /// <param name="targetType">The concrete service type.</param> /// <param name="container">The dependency container that contains the dependencies that will be used by the target type.</param> /// <param name="constructorResolver">The constructor resolver.</param> /// <param name="singletonEmitter">The emitter that will be responsible for emitting the singleton implementation.</param> public SingletonType(Type targetType, IDependencyContainer container, IConstructorResolver constructorResolver, ISingletonEmitter singletonEmitter) : this(new TransientType(targetType, container, constructorResolver), singletonEmitter) { }
/// <summary> /// Initializes a new instance of the SingletonType class. /// </summary> /// <param name="targetType">The concrete service type.</param> /// <param name="container">The dependency container that contains the dependencies that will be used by the target type.</param> /// <param name="constructorResolver">The constructor resolver.</param> /// <param name="singletonEmitter">The emitter that will be responsible for emitting the singleton implementation.</param> public SingletonType(System.Type targetType, IDependencyContainer container, IConstructorResolver constructorResolver, ISingletonEmitter singletonEmitter) : this(new TransientType(targetType, container, constructorResolver), singletonEmitter) { }
public DefaultActivator(ICompactContainer container, IConstructorResolver constructorResolver) { this.container = container; this.constructorResolver = constructorResolver; }
public SingletonFactory(Type implementationType, IConstructorResolver constructorResolver, IDependencyResolver dependencyResolver) : base(implementationType, constructorResolver, dependencyResolver) { }
protected void Reset() { _ctorResolver = null; Tracking.Clear(); }
public TransientFactory(Type implementationType, IConstructorResolver constructorResolver, IDependencyResolver dependencyResolver) { ConstructorResolver = constructorResolver; DependencyResolver = dependencyResolver; ImplementationType = implementationType; }
/// <summary> /// Initializes a new instance of the <see cref="DependencyMap"/> class. /// </summary> /// <param name="constructorResolver">The resolver that will be used to determine the constructor that will be used to instantiate a given object instance.</param> public DependencyMap(IConstructorResolver constructorResolver) : this(constructorResolver, new CachedContainerCompiler(new ContainerCompiler())) { }
/// <summary> /// Initializes a new instance of the SingletonType class. /// </summary> /// <param name="targetType">The concrete service type.</param> /// <param name="container">The dependency container that contains the dependencies that will be used by the target type.</param> /// <param name="constructorResolver">The constructor resolver.</param> public SingletonType(Type targetType, IDependencyContainer container, IConstructorResolver constructorResolver) : this(new TransientType(targetType, container, constructorResolver), new ContainerBasedSingletonEmitter()) { }
protected virtual IConstructorResolver GetConstructorResolver() { return(_ctorResolver ?? (_ctorResolver = new ConstructorResolver(this, Configurations.FirstOrDefault(p => p.Job == CurrentJob)))); }
/// <summary> /// Initializes a new instance of the SingletonType class. /// </summary> /// <param name="targetType">The concrete service type.</param> /// <param name="container">The dependency container that contains the dependencies that will be used by the target type.</param> /// <param name="constructorResolver">The constructor resolver.</param> public SingletonType(System.Type targetType, IDependencyContainer container, IConstructorResolver constructorResolver) : this(new TransientType(targetType, container, constructorResolver), new ContainerBasedSingletonEmitter()) { }
public void With(IConstructorResolver constructorResolver) => ConstructorResolver = constructorResolver;
public static IMethodCompiler <TDelegate> ResolveConstructorTo <[DelegateConstraint] TDelegate>(IConstructorResolver constructorInfoResolver) where TDelegate : class { Func <TDelegate> resolved = constructorInfoResolver.Resolve <TDelegate>(); return(new ConstructorExpressionizer <TDelegate>().From(resolved)); }