internal void Build(IEnumerable <TwinoServiceDescriptor> services) { BuildItem(new TwinoServiceDescriptor(ImplementationType.Singleton, typeof(IServiceProvider), GetType(), this), services); BuildItem(new TwinoServiceDescriptor(ImplementationType.Singleton, typeof(ITwinoServiceProvider), GetType(), this), services); BuildItem(new TwinoServiceDescriptor(ImplementationType.Singleton, typeof(IServiceContainer), GetType(), this), services); foreach (TwinoServiceDescriptor descriptor in services) { //skip microsoft's options open generic registrations if (descriptor.ImplementationType.IsGenericType && descriptor.ImplementationType.IsGenericTypeDefinition) { continue; } if (OptionsHelper.IsConfigurationType(descriptor.ServiceType)) { TwinoServiceDescriptor optionsDescriptor = CreateOptionsItem(descriptor); BuildItem(optionsDescriptor, services); } else { BuildItem(descriptor, services); } } foreach (KeyValuePair <Type, BuiltServiceDescriptor> pair in _services) { FillParameterDescriptors(pair.Value, pair.Value); } }
/// <summary> /// Finds a possible constructor that can be injected /// </summary> private ConstructorInfo FindPossibleConstructor(ConstructorInfo[] constructors) { foreach (ConstructorInfo ctor in constructors) { bool skip = false; ParameterInfo[] parameters = ctor.GetParameters(); foreach (ParameterInfo parameter in parameters) { bool paramFound = _services.Any(x => x.ServiceType == parameter.ParameterType || x.ImplementationType == parameter.ParameterType); if (!paramFound && !OptionsHelper.IsOptionsType(parameter.ParameterType) && !OptionsHelper.IsConfigurationType(parameter.ParameterType)) { skip = true; break; } if (parameter.ParameterType.IsPrimitive || parameter.ParameterType == typeof(decimal) || parameter.ParameterType == typeof(string)) { skip = true; break; } } if (!skip) { return(ctor); } } return(null); }