Пример #1
0
        public override IDependencyFactory GetFactory(IEnumerable <Type> genericTypeArguments)
        {
            Type derivedType = _genericTypeDefinition.MakeGenericType(genericTypeArguments as Type[] ?? genericTypeArguments.ToArray());

            if (_dependencyFactories.ContainsKey(derivedType))
            {
                return(_dependencyFactories[derivedType]);
            }

            ConstructorInfo derivedConstructor = derivedType.GetTypeInfo().DeclaredConstructors.Where(x => x.IsPublic).ElementAt(_constructorIndex);
            IResolvableRejecter <object, IEnumerable, IEnumerable, object> resolvableDerivedConstructor = derivedConstructor.AsResolvableRejecter();

            IDependencyFactory factory;

            switch (InstanceOrigin)
            {
            case Niddle.InstanceOrigin.Instantiation:
                factory = new NewInstanceFactory(derivedType, null, resolvableDerivedConstructor, Substitution.Forbidden, _resolvableMembersProvider);
                break;

            case Niddle.InstanceOrigin.Registration:
                factory = new SingletonFactory(derivedType, null, resolvableDerivedConstructor, Substitution.Forbidden, _resolvableMembersProvider);
                break;

            default:
                throw new ArgumentException();
            }

            _dependencyFactories.Add(derivedType, factory);
            return(factory);
        }
Пример #2
0
 public NewInstanceFactory(Type type, object serviceKey, IResolvableRejecter <object, IEnumerable, IEnumerable, object> resolvableInstantiator, Substitution substitution,
                           IResolvableMembersProvider <object> resolvableMembersProvider = null)
     : base(type, serviceKey, substitution)
 {
     _resolvableInstantiator    = resolvableInstantiator;
     _resolvableMembersProvider = resolvableMembersProvider;
 }
Пример #3
0
        protected override IDependencyFactory Build()
        {
            if (Instance != null)
            {
                return(new InstanceFactory(Type, Instance, Key, Substitution));
            }

            IResolvableRejecter <object, IEnumerable, IEnumerable, object> instantiator =
                Instantiator
                ?? ReflectionHelper.GetDefaultConstructor(Type).AsResolvableRejecter <object>();

            return(Singleton
                ? new SingletonFactory(Type, Key, instantiator, Substitution, ResolvableMembersProvider)
                : new NewInstanceFactory(Type, Key, instantiator, Substitution, ResolvableMembersProvider));
        }
Пример #4
0
 public SingletonFactory(Type type, object serviceKey, IResolvableRejecter <object, IEnumerable, IEnumerable, object> resolvableInstantiator, Substitution substitution,
                         IResolvableMembersProvider <object> resolvableMembersProvider = null)
     : base(type, serviceKey, resolvableInstantiator, substitution, resolvableMembersProvider)
 {
 }
Пример #5
0
 public ITypeDependencyBuilder <T> Creating(MethodInfo methodInfo)
 {
     Instantiator = methodInfo.AsResolvableRejecter();
     return(Builder);
 }
Пример #6
0
 public ITypeDependencyBuilder <T> Creating(ConstructorInfo constructorInfo)
 {
     Instantiator = constructorInfo.AsResolvableRejecter();
     return(Builder);
 }