public static void AddControllersAsServices(IServiceCollection services, IEnumerable<Assembly> assemblies)
        {
            var assemblyProvider = new FixedSetAssemblyProvider();
            foreach (var assembly in assemblies)
            {
                assemblyProvider.CandidateAssemblies.Add(assembly);
            }

            var controllerTypeProvider = new DefaultControllerTypeProvider(assemblyProvider);
            var controllerTypes = controllerTypeProvider.ControllerTypes;

            AddControllersAsServices(services, controllerTypes.Select(type => type.AsType()));
        }
示例#2
0
        public static void AddControllersAsServices(IServiceCollection services, IEnumerable <Assembly> assemblies)
        {
            var assemblyProvider = new StaticAssemblyProvider();

            foreach (var assembly in assemblies)
            {
                assemblyProvider.CandidateAssemblies.Add(assembly);
            }

            var controllerTypeProvider = new DefaultControllerTypeProvider(assemblyProvider);
            var controllerTypes        = controllerTypeProvider.ControllerTypes;

            AddControllersAsServices(services, controllerTypes.Select(type => type.AsType()));
        }
示例#3
0
        /// <summary>
        /// Registers controller types from the specified <paramref name="assemblies"/> as services and as a source
        /// for controller discovery.
        /// </summary>
        /// <param name="services">The <see cref="IServiceCollection"/>.</param>
        /// <param name="controllerAssemblies">Assemblies to scan.</param>
        /// <returns>The <see cref="IServiceCollection"/>.</returns>
        public static IServiceCollection WithControllersAsServices(
            [NotNull] this IServiceCollection services,
            [NotNull] IEnumerable <Assembly> controllerAssemblies)
        {
            var assemblyProvider = new FixedSetAssemblyProvider();

            foreach (var assembly in controllerAssemblies)
            {
                assemblyProvider.CandidateAssemblies.Add(assembly);
            }

            var controllerTypeProvider = new DefaultControllerTypeProvider(assemblyProvider);
            var controllerTypes        = controllerTypeProvider.ControllerTypes;

            return(WithControllersAsServices(services, controllerTypes.Select(type => type.AsType())));
        }