Skip to content

Commit

Permalink
AddControllersWithViewsCore should add CacheTagHelper services (#9580)
Browse files Browse the repository at this point in the history
  • Loading branch information
pranavkm committed Apr 21, 2019
1 parent 5e95312 commit 0303c9e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Mvc/Mvc/src/MvcServiceCollectionExtensions.cs
Expand Up @@ -227,7 +227,10 @@ public static IMvcBuilder AddControllersWithViews(this IServiceCollection servic

private static IMvcCoreBuilder AddControllersWithViewsCore(IServiceCollection services)
{
var builder = AddControllersCore(services).AddViews().AddRazorViewEngine();
var builder = AddControllersCore(services)
.AddViews()
.AddRazorViewEngine()
.AddCacheTagHelper();

AddTagHelpersFrameworkParts(builder.PartManager);

Expand Down
32 changes: 32 additions & 0 deletions src/Mvc/Mvc/test/MvcServiceCollectionExtensionsTest.cs
Expand Up @@ -15,12 +15,15 @@
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;
Expand Down Expand Up @@ -219,6 +222,35 @@ public void AddRazorPages_Twice_DoesNotAddDuplicates()
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<MvcOptions>) && 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;
Expand Down

0 comments on commit 0303c9e

Please sign in to comment.