Exemplo n.º 1
0
        public static IEnumerable <Type> GetImplementType(this Type intefaceType)
        {
            var types = new List <Type>();

            foreach (var lib in RuntimeHelper.GetDependencyAssemblies())
            {
                if (lib.GetTypes().Any(t => !t.IsInterface && !t.IsAbstract && intefaceType.IsAssignableFrom(t)))
                {
                    var implementTypes = lib.GetTypes().Where(t => !t.IsInterface && !t.IsAbstract && intefaceType.IsAssignableFrom(t));
                    types.AddRange(implementTypes);
                }
            }
            return(types);
        }
Exemplo n.º 2
0
        public static IServiceCollection AddAssemblyTypes(this IServiceCollection services)
        {
            var interfaces = RuntimeHelper.GetAssemblyInterfaces();

            foreach (var @interface in interfaces)
            {
                var implementType = @interface.GetImplementType().FirstOrDefault();
                if (implementType == null)
                {
                    continue;
                }
                services.AddScoped(@interface, implementType);
            }

            return(services);
        }