private object Resolve(Type dependencyType, ImplementationName implementationName = ImplementationName.None) { if (dependencyType.IsGenericType && (dependencyType.GetGenericTypeDefinition() == typeof(IEnumerable <>))) { return(GetAllImplementations(dependencyType.GetGenericArguments()[0])); } if (dependencyType.IsGenericType && dependencies.ContainsKey(dependencyType.GetGenericTypeDefinition())) { var implementationType = dependencies[dependencyType.GetGenericTypeDefinition()][0].ImplementationType; implementationType = implementationType.MakeGenericType(dependencyType.GetGenericArguments()); if (dependencyType.IsAssignableFrom(implementationType)) { return(CreateInstance(implementationType)); } } if (!dependencies.ContainsKey(dependencyType)) { return(null); } var implementationInfo = GetImplementationInfo(dependencyType, implementationName); if (!dependencyType.IsAssignableFrom(implementationInfo.ImplementationType)) { return(null); } if (implementationInfo.Lifetime == LifeTime.Transient) { return(CreateInstance(implementationInfo.ImplementationType)); } if (implementationInfo.Lifetime == LifeTime.Singleton) { return(Singleton.GetInstance(implementationInfo.ImplementationType, CreateInstance)); } return(null); }
public AttributeDependencyKey(ImplementationName name) { ImplementationName = name; }
private DependencyInfo GetImplementationInfo(Type dependencyType, ImplementationName name) { var implementations = dependencies[dependencyType]; return(implementations.Where(info => info.Name == name).First()); }
public T Resolve <T>(ImplementationName implementationName = ImplementationName.None) where T : class { Type dependencyType = typeof(T); return((T)Resolve(dependencyType, implementationName)); }
public DependencyKeyAttribute(ImplementationName implementationName) { ImplementationName = implementationName; }
public ImplementationInfo(Type type, Lifetime lifetime, ImplementationName name) { Lifetime = lifetime; ImplementationType = type; Name = name; }
protected virtual bool ImplementationNameTest(FeatureName name) { return(name.ToString() == ImplementationName.ToString()); }
public void Register <TDependency, TImplementation>(Lifetime lifetime = Lifetime.Transient, ImplementationName name = ImplementationName.None) where TDependency : class where TImplementation : TDependency { var implementationInfo = new ImplementationInfo(typeof(TImplementation), lifetime, name); if (Dependencies.ContainsKey(typeof(TDependency))) { Dependencies[typeof(TDependency)].Add(implementationInfo); } else { Dependencies.Add(typeof(TDependency), new List <ImplementationInfo>()); Dependencies[typeof(TDependency)].Add(implementationInfo); } }
public T Resolver <T>(ImplementationName implementationName = ImplementationName.None) { Type serviceType = typeof(T); return((T)ResolveCommon(serviceType, implementationName)); }
object Resolver(Type serviceType, ImplementationName implementationName = ImplementationName.None) { return(ResolveCommon(serviceType, implementationName)); }
public DependencyInfo(Type type, LifeTime lifetime, ImplementationName name) { Lifetime = lifetime; ImplementationType = type; Name = name; }