Esempio n. 1
0
        public void Add(ImplementationInfo implementation)
        {
            ImplementationInfo listRunner = this;

            while (listRunner.NextImplementation != null)
            {
                listRunner = listRunner.NextImplementation;
            }
            listRunner.NextImplementation = implementation;
        }
Esempio n. 2
0
        public void RegisterTransient <TDependency, TImplementation>(
            ImplementationName implementationName = ImplementationName.None) where TImplementation : TDependency
        {
            var implementationInfo = new ImplementationInfo()
            {
                Lifetime = Lifetime.Transient, TImplementation = typeof(TImplementation), ImplementationName = implementationName
            };

            Register <TDependency>(implementationInfo);
        }
Esempio n. 3
0
 void Register <TDependency>(ImplementationInfo implementationInfo)
 {
     if (dependencies.ContainsKey(typeof(TDependency)))
     {
         dependencies[typeof(TDependency)].Add(implementationInfo);
     }
     else
     {
         dependencies.Add(typeof(TDependency), implementationInfo);
     }
 }
 //here validation for singleton
 private object GetInstance(ImplementationInfo tImplementation)
 {
     if (tImplementation.isSingleton)
     {
         return(tImplementation.GetInstance(this));
     }
     else
     {
         return(Create(tImplementation.implementationType));
     }
 }
Esempio n. 5
0
        public IEnumerable <ImplementationInfo> ImplementationList()
        {
            ImplementationInfo runner = this;

            while (runner != null)
            {
                yield return(runner);

                runner = runner.NextImplementation;
            }
        }
        public void Register(Type dependencyType, Type implementationType)
        {
            var implementationInfo = new ImplementationInfo(implementationType, Lifetime.Transient, ImplementationVariant.None);

            if (Dependencies.ContainsKey(dependencyType))
            {
                Dependencies[dependencyType].Add(implementationInfo);
            }
            else
            {
                Dependencies.Add(dependencyType, new List <ImplementationInfo>());
                Dependencies[dependencyType].Add(implementationInfo);
            }
        }
        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);
            }
        }
Esempio n. 8
0
        public void Register(Type typeDependency, Type typeImplementation)
        {
            var implemetationInfo = new ImplementationInfo()
            {
                Lifetime = Lifetime.Transient, TImplementation = typeImplementation
            };

            if (openGenericDependencies.ContainsKey(typeDependency))
            {
                openGenericDependencies[typeDependency].Add(implemetationInfo);
            }
            else
            {
                openGenericDependencies.Add(typeDependency, implemetationInfo);
            }
        }
Esempio n. 9
0
        object ResolveCommon(Type serviceType, ImplementationName implementationName)
        {
            if (serviceType.IsGenericType &&
                (serviceType.GetGenericTypeDefinition() == typeof(IEnumerable <>)))
            {
                return(GetEnumerable(serviceType.GetGenericArguments()[0]));
            }

            if (serviceType.IsGenericType &&
                openGenericDependecies.ContainsKey(serviceType.GetGenericTypeDefinition()))
            {
                Type implemetationType = openGenericDependecies[serviceType.GetGenericTypeDefinition()].TImplementation;
                implemetationType = implemetationType.MakeGenericType(serviceType.GetGenericArguments());
                var implemetation = new ImplementationInfo()
                {
                    Lifetime = Lifetime.Transient, TImplementation = implemetationType
                };
                dependencies.Add(serviceType, implemetation);
            }

            if (!dependencies.ContainsKey(serviceType))
            {
                return(null);
            }

            var implementationInfo = getImplemetationInfo(serviceType, implementationName);

            if (!serviceType.IsAssignableFrom(implementationInfo.TImplementation))
            {
                return(null);
            }

            if (implementationInfo.Lifetime == Lifetime.Singleton)
            {
                return(Singleton.GetInstance(implementationInfo.TImplementation, CreateImplemetationInstance));
            }

            if (implementationInfo.Lifetime == Lifetime.Transient)
            {
                return(CreateImplemetationInstance(implementationInfo.TImplementation));
            }

            return(null);
        }