コード例 #1
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 loggerFactory = new LoggerFactory();
            var controllerTypeProvider = new DefaultControllerTypeProvider(assemblyProvider, loggerFactory);
            var controllerTypes = controllerTypeProvider.ControllerTypes;

            return WithControllersAsServices(services, controllerTypes.Select(type => type.AsType()));
        }
コード例 #2
0
        private ControllerActionDescriptorProvider CreateProvider()
        {
            var assemblyProvider = new FixedSetAssemblyProvider();
            assemblyProvider.CandidateAssemblies.Add(GetType().GetTypeInfo().Assembly);
            var controllerTypeProvider = new NamespaceFilteredControllerTypeProvider(assemblyProvider);
            var modelBuilder = new DefaultControllerModelBuilder(new DefaultActionModelBuilder(null), null);

            var filterProvider = new Mock<IGlobalFilterProvider>();
            filterProvider
                .SetupGet(fp => fp.Filters)
                .Returns(new List<IFilter>());

            var options = new MvcOptions();

            var setup = new WebApiCompatShimOptionsSetup();
            setup.Configure(options);

            var optionsAccessor = new Mock<IOptions<MvcOptions>>();
            optionsAccessor
                .SetupGet(o => o.Options)
                .Returns(options);

            var provider = new ControllerActionDescriptorProvider(
                controllerTypeProvider,
                modelBuilder,
                filterProvider.Object,
                optionsAccessor.Object);

            return provider;
        }
コード例 #3
0
        private static DefaultControllerTypeProvider GetControllerTypeProvider()
        {
            var assemblyProvider = new FixedSetAssemblyProvider();

            return(new DefaultControllerTypeProvider(assemblyProvider, NullLoggerFactory.Instance));
        }
コード例 #4
0
        private ControllerActionDescriptorProvider CreateProvider()
        {
            var assemblyProvider = new FixedSetAssemblyProvider();
            assemblyProvider.CandidateAssemblies.Add(GetType().GetTypeInfo().Assembly);
            var controllerTypeProvider = new NamespaceFilteredControllerTypeProvider(assemblyProvider);

            var options = new MvcOptions();

            var setup = new WebApiCompatShimOptionsSetup();
            setup.Configure(options);

            var optionsAccessor = new Mock<IOptions<MvcOptions>>();
            optionsAccessor
                .SetupGet(o => o.Options)
                .Returns(options);

            var authorizationOptionsAccessor = new Mock<IOptions<AuthorizationOptions>>();
            authorizationOptionsAccessor
                .SetupGet(o => o.Options)
                .Returns(new AuthorizationOptions());

            var modelProvider = new DefaultApplicationModelProvider(optionsAccessor.Object);

            var provider = new ControllerActionDescriptorProvider(
                controllerTypeProvider,
                new[] { modelProvider },
                optionsAccessor.Object);

            return provider;
        }
コード例 #5
0
        private static DefaultControllerTypeProvider GetControllerTypeProvider()
        {
            var assemblyProvider = new FixedSetAssemblyProvider();

            return(new DefaultControllerTypeProvider(assemblyProvider));
        }