Ejemplo n.º 1
0
        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}");
        }
Ejemplo n.º 2
0
 /// <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);
 }
Ejemplo n.º 3
0
 public object Activate(Type type)
 {
     return(SimpleActivator.Activate(type, this));
 }