예제 #1
0
파일: Container.cs 프로젝트: naice/Jens
        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}");
        }
예제 #2
0
파일: Container.cs 프로젝트: naice/Jens
 /// <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);
 }
예제 #3
0
파일: Container.cs 프로젝트: naice/Jens
 public object Activate(Type type)
 {
     return(SimpleActivator.Activate(type, this));
 }