예제 #1
0
 /// <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;
 }
예제 #2
0
 /// <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;
 }
예제 #3
0
        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);
                    }
                }
            }
        }
예제 #4
0
        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);
        }
예제 #5
0
        /// <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);
            };
        }
예제 #6
0
        /// <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;
 }
예제 #8
0
 /// <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));
 }
예제 #9
0
 /// <summary>
 /// Initializes a new instance of the DependencyMapLoader class.
 /// </summary>
 public DependencyMapLoader(IConstructorResolver constructorResolver)
     : this(constructorResolver, new TypeLoader(), new ServiceLoader(), new DefaultServiceResolver())
 {
 }
예제 #10
0
 public static Expression?ResolveConstructorExpression(this IConstructorResolver resolver, Type type)
 {
     return(resolver.ResolveConstructorExpression(type, resolver.StaticSelectConstructor(type)));
 }
예제 #11
0
 public ConstructorResolverTests()
 {
     container           = new Mock <IContainer>();
     constructorResolver = new ConstructorResolver(container.Object);
 }
예제 #12
0
 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}"));
 }
예제 #14
0
 /// <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));
 }
예제 #15
0
 /// <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)
 {
 }
예제 #16
0
 /// <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)
 {
 }
예제 #17
0
 public DefaultActivator(ICompactContainer container, IConstructorResolver constructorResolver)
 {
     this.container           = container;
     this.constructorResolver = constructorResolver;
 }
예제 #18
0
 public SingletonFactory(Type implementationType, IConstructorResolver constructorResolver, IDependencyResolver dependencyResolver)
     : base(implementationType, constructorResolver, dependencyResolver)
 {
 }
예제 #19
0
 protected void Reset()
 {
     _ctorResolver = null;
     Tracking.Clear();
 }
예제 #20
0
 public TransientFactory(Type implementationType, IConstructorResolver constructorResolver, IDependencyResolver dependencyResolver)
 {
     ConstructorResolver = constructorResolver;
     DependencyResolver  = dependencyResolver;
     ImplementationType  = implementationType;
 }
예제 #21
0
 /// <summary>
 /// Initializes a new instance of the DependencyMapLoader class.
 /// </summary>
 public DependencyMapLoader(IConstructorResolver constructorResolver)
     : this(constructorResolver, new TypeLoader(), new ServiceLoader(), new DefaultServiceResolver())
 {
 }
예제 #22
0
 /// <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()))
 {
 }
예제 #23
0
 /// <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())
 {
 }
예제 #24
0
 protected virtual IConstructorResolver GetConstructorResolver()
 {
     return(_ctorResolver ?? (_ctorResolver = new ConstructorResolver(this, Configurations.FirstOrDefault(p => p.Job == CurrentJob))));
 }
예제 #25
0
 /// <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())
 {
 }
예제 #26
0
 public void With(IConstructorResolver constructorResolver) => ConstructorResolver = constructorResolver;
예제 #27
0
        public static IMethodCompiler <TDelegate> ResolveConstructorTo <[DelegateConstraint] TDelegate>(IConstructorResolver constructorInfoResolver) where TDelegate : class
        {
            Func <TDelegate> resolved = constructorInfoResolver.Resolve <TDelegate>();

            return(new ConstructorExpressionizer <TDelegate>().From(resolved));
        }