public object GetDependency(Type dependencyType) { // return this container as it resolves. if (dependencyType == typeof(IDependencyResolver)) { return(this); } var resolvedType = ResolveDependencyType(dependencyType); if (resolvedType != null) { // check for singleton existing. if (_dependencySingletonContainer.ContainsKey(resolvedType)) { return(_dependencySingletonContainer[resolvedType].Value); } // return activated instance. return(SimpleActivator.Activate(resolvedType, this)); } throw new InvalidOperationException($"Unknown dependency, please register type {dependencyType.FullName}"); }
/// <summary> /// [Lazy] Register Singleton of Type T. /// </summary> public Container WithSingleton <T>() where T : class { WithSingleton(new Lazy <T>(() => SimpleActivator.Activate(typeof(T), this) as T)); return(this); }
public object Activate(Type type) { return(SimpleActivator.Activate(type, this)); }