public void ReflectorReturnsCorrectCtorInjectionPointForNamedParamsCtor() { ConstructorInjectionPoint injectionPoint = reflector.DescribeInjections(typeof(OneNamedParameterConstructorInjectee)).ctor; Assert.True(injectionPoint is ConstructorInjectionPoint, "reflector-returned injectionPoint is ctor injectionPoint"); injector.Map(typeof(Clazz), InjectEnum.NAMED_DEPENDENCY).ToType(typeof(Clazz)); OneNamedParameterConstructorInjectee injectee = injectionPoint.CreateInstance(typeof(OneNamedParameterConstructorInjectee), injector) as OneNamedParameterConstructorInjectee; Assert.NotNull(injectee.GetDependency(), "Instance of Clazz should have been injected for named Clazz parameter"); }
public void ReflectorGetsOptionalInCtorInjectionPoint() { ConstructorInjectionPoint injectionPoint = reflector.DescribeInjections(typeof(OptionalConstructorInjectee)).ctor; string value2 = "Value2"; Assert.That(injectionPoint, Is.InstanceOf <ConstructorInjectionPoint> ()); injector.Map(typeof(string)).ToValue(value2); OptionalConstructorInjectee injectee = injectionPoint.CreateInstance(typeof(OptionalConstructorInjectee), injector) as OptionalConstructorInjectee; Assert.That(injectee.param1, Is.EqualTo(0)); Assert.That(injectee.param2, Is.EqualTo(value2)); }
public object GetInstance(Type type, object key = null, Type targetType = null) { MappingId mappingId = new MappingId(type, key); DependencyProvider provider = GetProvider(mappingId); if (provider == null) { provider = GetDefaultProvider(mappingId, true); } if (provider != null) { // ConstructorInjectionPoint ctor = _typeDescriptor.GetDescription(type).ctor; //TODO: Make this CTOR ConstructorInjectionPoint ctor = null; return(provider.Apply(targetType, this, ctor != null ? ctor.injectParameters : null)); } string fallbackMessage = _fallbackProvider != null ? "the fallbackProvider, '" + _fallbackProvider + "', was unable to fulfill this request." : "the injector has no fallbackProvider."; throw new InjectorMissingMappingException("No mapping found for request " + mappingId + " and " + fallbackMessage); }