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); }
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; }
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)); }
public SingletonFactory(Type type, object serviceKey, IResolvableRejecter <object, IEnumerable, IEnumerable, object> resolvableInstantiator, Substitution substitution, IResolvableMembersProvider <object> resolvableMembersProvider = null) : base(type, serviceKey, resolvableInstantiator, substitution, resolvableMembersProvider) { }
public ITypeDependencyBuilder <T> Creating(MethodInfo methodInfo) { Instantiator = methodInfo.AsResolvableRejecter(); return(Builder); }
public ITypeDependencyBuilder <T> Creating(ConstructorInfo constructorInfo) { Instantiator = constructorInfo.AsResolvableRejecter(); return(Builder); }