diff --git a/src/Mvc/Mvc/src/MvcServiceCollectionExtensions.cs b/src/Mvc/Mvc/src/MvcServiceCollectionExtensions.cs index ffb69ee504..1dc105ee9d 100644 --- a/src/Mvc/Mvc/src/MvcServiceCollectionExtensions.cs +++ b/src/Mvc/Mvc/src/MvcServiceCollectionExtensions.cs @@ -227,7 +227,10 @@ namespace Microsoft.Extensions.DependencyInjection private static IMvcCoreBuilder AddControllersWithViewsCore(IServiceCollection services) { - var builder = AddControllersCore(services).AddViews().AddRazorViewEngine(); + var builder = AddControllersCore(services) + .AddViews() + .AddRazorViewEngine() + .AddCacheTagHelper(); AddTagHelpersFrameworkParts(builder.PartManager); diff --git a/src/Mvc/Mvc/test/MvcServiceCollectionExtensionsTest.cs b/src/Mvc/Mvc/test/MvcServiceCollectionExtensionsTest.cs index c7dadf76b5..b20563dcfe 100644 --- a/src/Mvc/Mvc/test/MvcServiceCollectionExtensionsTest.cs +++ b/src/Mvc/Mvc/test/MvcServiceCollectionExtensionsTest.cs @@ -15,12 +15,15 @@ using Microsoft.AspNetCore.Mvc.ApplicationParts; using Microsoft.AspNetCore.Mvc.Controllers; using Microsoft.AspNetCore.Mvc.Cors; using Microsoft.AspNetCore.Mvc.Filters; +using Microsoft.AspNetCore.Mvc.Formatters; using Microsoft.AspNetCore.Mvc.Infrastructure; using Microsoft.AspNetCore.Mvc.Razor; using Microsoft.AspNetCore.Mvc.Razor.TagHelpers; using Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure; +using Microsoft.AspNetCore.Mvc.Rendering; using Microsoft.AspNetCore.Mvc.TagHelpers; using Microsoft.AspNetCore.Mvc.ViewComponents; +using Microsoft.AspNetCore.Mvc.ViewEngines; using Microsoft.AspNetCore.Mvc.ViewFeatures; using Microsoft.AspNetCore.Mvc.ViewFeatures.Filters; using Microsoft.AspNetCore.Routing; @@ -219,6 +222,35 @@ namespace Microsoft.AspNetCore.Mvc VerifyAllServices(services); } + [Fact] + public void AddControllersWithViews_AddsDocumentedServices() + { + // Arrange + var services = new ServiceCollection(); + services.AddControllersWithViews(); + + // Assert + // Adds controllers + Assert.Contains(services, s => s.ServiceType == typeof(IActionInvokerProvider) && s.ImplementationType == typeof(ControllerActionInvokerProvider)); + // Adds ApiExplorer + Assert.Contains(services, s => s.ServiceType == typeof(IApiDescriptionGroupCollectionProvider)); + // Adds CORS + Assert.Contains(services, s => s.ServiceType == typeof(CorsAuthorizationFilter)); + // Adds DataAnnotations + Assert.Contains(services, s => s.ServiceType == typeof(IConfigureOptions) && s.ImplementationType == typeof(MvcDataAnnotationsMvcOptionsSetup)); + // Adds FormatterMappings + Assert.Contains(services, s => s.ServiceType == typeof(FormatFilter)); + // Adds Views + Assert.Contains(services, s => s.ServiceType == typeof(IHtmlHelper)); + // Adds Razor + Assert.Contains(services, s => s.ServiceType == typeof(IRazorViewEngine)); + // Adds CacheTagHelper + Assert.Contains(services, s => s.ServiceType == typeof(CacheTagHelperMemoryCacheFactory)); + + // No Razor Pages + Assert.Empty(services.Where(s => s.ServiceType == typeof(IActionInvokerProvider) && s.ImplementationType == typeof(PageActionInvokerProvider))); + } + private void VerifyAllServices(IServiceCollection services) { var singleRegistrationServiceTypes = SingleRegistrationServiceTypes;