public static void AddControllersAsServices(IServiceCollection services, IEnumerable<Type> types)
        {
            var controllerTypeProvider = new StaticControllerTypeProvider();
            foreach (var type in types)
            {
                services.TryAddTransient(type, type);
                controllerTypeProvider.ControllerTypes.Add(type.GetTypeInfo());
            }

            services.Replace(ServiceDescriptor.Transient<IControllerActivator, ServiceBasedControllerActivator>());
            services.Replace(ServiceDescriptor.Singleton<IControllerTypeProvider>(controllerTypeProvider));
        }
        private ControllerActionDescriptorProvider GetProvider(
            TypeInfo controllerTypeInfo,
            IApplicationModelConvention convention)
        {
            var options = new TestOptionsManager<MvcOptions>();
            options.Value.Conventions.Add(convention);

            var controllerTypeProvider = new StaticControllerTypeProvider(new[] { controllerTypeInfo });
            var modelProvider = new DefaultApplicationModelProvider(options);

            var provider = new ControllerActionDescriptorProvider(
                controllerTypeProvider,
                new[] { modelProvider },
                options);

            return provider;
        }
        private ControllerActionDescriptorProvider GetProvider(
            params TypeInfo[] controllerTypeInfos)
        {
            var options = new TestOptionsManager<MvcOptions>();

            var controllerTypeProvider = new StaticControllerTypeProvider(controllerTypeInfos);
            var modelProvider = new DefaultApplicationModelProvider(options);

            var provider = new ControllerActionDescriptorProvider(
                controllerTypeProvider,
                new[] { modelProvider },
                options);

            return provider;
        }
        private ControllerActionDescriptorProvider GetProvider(
            TypeInfo controllerTypeInfo,
            IEnumerable<IFilterMetadata> filters = null)
        {
            var options = new TestOptionsManager<MvcOptions>();
            if (filters != null)
            {
                foreach (var filter in filters)
                {
                    options.Value.Filters.Add(filter);
                }
            }

            var controllerTypeProvider = new StaticControllerTypeProvider(new[] { controllerTypeInfo });
            var modelProvider = new DefaultApplicationModelProvider(options);

            var provider = new ControllerActionDescriptorProvider(
                controllerTypeProvider,
                new[] { modelProvider },
                options);

            return provider;
        }
        private ControllerActionDescriptorProvider GetActionDescriptorProvider()
        {
            var controllerTypes = typeof(DefaultActionSelectorTests)
                .GetNestedTypes(BindingFlags.NonPublic)
                .Select(t => t.GetTypeInfo())
                .ToList();

            var options = new TestOptionsManager<MvcOptions>();

            var controllerTypeProvider = new StaticControllerTypeProvider(controllerTypes);
            var modelProvider = new DefaultApplicationModelProvider(options);

            var provider = new ControllerActionDescriptorProvider(
                controllerTypeProvider,
                new[] { modelProvider },
                options);

            return provider;
        }