/// <summary>
        /// Loads the DLL's and scans their types using Reflection. If a class implementing
        /// <see cref="ITypeRegistrar"/> is found, it is executed, thus adding these types to
        /// the DI container.
        /// </summary>
        /// <param name="services">The <see cref="IServiceCollection"/> to register the types in.</param>
        /// <param name="inheritedTypesRegistry">The <see cref="IInheritedTypesRegistry"/>> to resolve inherited types.</param>
        /// <param name="dllFiles">The paths of all dll files to scan.</param>
        public static void LoadConfiguredTypesFromFiles(
            this IServiceCollection services, IInheritedTypesRegistry inheritedTypesRegistry, IEnumerable <string> dllFiles)
        {
            var container = new TypeRegistrationContainer(services);

            foreach (var dllFile in dllFiles)
            {
                LoadAssembly(container, inheritedTypesRegistry, dllFile);
            }
        }
        private static void LoadAssembly(ITypeRegistrationContainer container, IInheritedTypesRegistry inheritedTypesRegistry, string dllFile)
        {
            var assembly = Assembly.LoadFile(dllFile);

            var types = assembly.GetTypes();

            foreach (var registrarType in types
                     .Where(t => typeof(ITypeRegistrar).IsAssignableFrom(t) && t.IsClass && !t.IsAbstract))
            {
                RunRegistrar(container, registrarType);
            }

            foreach (var typeRegistrarType in types
                     .Where(t => typeof(IInheritedTypeRegistrar).IsAssignableFrom(t) && t.IsClass && !t.IsAbstract))
            {
                RunInheritedTypesRegistrar(inheritedTypesRegistry, typeRegistrarType);
            }
        }
 public void RegisterInheritedTypes(IInheritedTypesRegistry registry)
 {
     registry.RegisterInheritedType <Toy, Marble>("Marble");
 }
        private static void RunInheritedTypesRegistrar(IInheritedTypesRegistry typeRegistry, Type typeRegistrarType)
        {
            var registrar = (IInheritedTypeRegistrar)Activator.CreateInstance(typeRegistrarType);

            registrar.RegisterInheritedTypes(typeRegistry);
        }
 public void RegisterInheritedTypes(IInheritedTypesRegistry registry)
 {
     registry.RegisterInheritedType <Toy, LegoSet>("LegoSet");
 }