Skip to content

Instantly share code, notes, and snippets.

@scottsauber
Last active May 3, 2020 19:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scottsauber/e73a623092eb224fc402a171e7500c14 to your computer and use it in GitHub Desktop.
Save scottsauber/e73a623092eb224fc402a171e7500c14 to your computer and use it in GitHub Desktop.
using System.Collections.Generic;
using JetBrains.Annotations;
using Microsoft.AspNetCore.Mvc.Razor;
// These annotations make Resharper not complain about not finding the Views.
// ASP.NET Core support coming to R# for Feature Folders soon - https://youtrack.jetbrains.com/issue/RSRP-461882
[assembly: AspMvcViewLocationFormat("/Features/{1}/{0}.cshtml")]
[assembly: AspMvcViewLocationFormat("/Features/Shared/{0}.cshtml")]
[assembly: AspMvcPartialViewLocationFormat("~/Features/{1}/{0}.cshtml")]
[assembly: AspMvcPartialViewLocationFormat("~/Features/Shared/{0}.cshtml")]
namespace WebApplication1.Infrastructure.StartupCustomizations
{
public class FeatureFolderLocationExpander : IViewLocationExpander
{
public void PopulateValues(ViewLocationExpanderContext context)
{
// Don't need anything here, but required by the interface
}
public IEnumerable<string> ExpandViewLocations(ViewLocationExpanderContext context, IEnumerable<string> viewLocations)
{
// The old locations are /Views/{1}/{0}.cshtml and /Views/Shared/{0}.cshtml where {1} is the controller and {0} is the name of the View
// Replace /Views with /Features
return new[]
{
"/Features/{1}/{0}.cshtml",
"/Features/Shared/{0}.cshtml"
};
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment