public Object Resolve <TDependency>() where TDependency : class { Type dependencyType = typeof(TDependency); if (typeof(IEnumerable).IsAssignableFrom(dependencyType)) { Type genericType = dependencyType.GetGenericArguments()[0]; List <Object> list = new List <object>(); foreach (var implementationInfo in _configuration.GetAllImplementationTypes(genericType)) { list.Add(Resolve(implementationInfo)); } return(list.AsEnumerable()); } if (_configuration.Has(dependencyType)) { ImplementationInfo implementationInfo = _configuration.GetFirstImplementationType(dependencyType); return(Resolve(implementationInfo) as TDependency); } if (dependencyType.IsGenericType) { Type genericBase = dependencyType.GetGenericTypeDefinition(); Type genericArgument = dependencyType.GetGenericArguments()[0]; if (_configuration.Has(genericBase) && _configuration.Has(genericArgument)) { return(ResolveOpenGeneric(_configuration.GetFirstImplementationType(genericBase).Type, genericArgument) as TDependency); } } throw new Exception("Not supported type"); }
private Object Resolve(ImplementationInfo implementationInfo) { Type type = implementationInfo.Type; if (implementationInfo.IsSingleton && implementationInfo.GetValue() != null) { return(implementationInfo.GetValue()); } Object value = CreateObject(type); if (implementationInfo.IsSingleton) { implementationInfo.SetValue(value); } return(value); }