Exemplo n.º 1
0
        public List <Type> FindImplemenationsOf(Type serviceType)
        {
            return(_typeCache
                   .GetTypes(AutoType.Implementation)
                   .Where(x => !x.IsAbstract)
                   .Where(IsServiceImplementation).ToList());

            bool IsServiceImplementation(Type concreteType)
            {
                var interfaces = concreteType.GetInterfaces();

                if (!interfaces.Any())
                {
                    return(false);
                }

                return(interfaces.Any(x => x == serviceType) ||
                       interfaces.Any(@interface => IsGenericTypeImplementation(serviceType, @interface)));
            }
        }
        public void Populate(IServiceCollection serviceCollection, LifeTime lifeTime, bool includeOpenGenericWireup)
        {
            foreach (var abstraction in _typeCache.GetTypes(AutoType.Abstraction))
            {
                var types = _implementationsFinder.FindImplemenationsOf(abstraction);
                if (!includeOpenGenericWireup && types.All(x => x.IsGenericType))
                {
                    return;
                }

                var dependencyType = types.FirstOrDefault(type => _serviceTypeNameFilter.IsMatch(abstraction, type));

                switch (lifeTime)
                {
                case LifeTime.Singleton:
                    RegisterDependency(serviceCollection.AddSingleton, abstraction, dependencyType);
                    break;

                case LifeTime.Transient:
                    RegisterDependency(serviceCollection.AddTransient, abstraction, dependencyType);
                    break;
                }
            }
        }
Exemplo n.º 3
0
 public IEnumerable <Type> GetTypes(Type baseType)
 {
     return(_cache.GetTypes(baseType));
 }