This repository was archived by the owner on Dec 14, 2018. It is now read-only.

Description
In Mvc 5, the VirtualPathProviderViewEngine that was the base for all view engines that shipped in the box looked for views in a very specific set of locations that were exposed as properties of that type.
The primary way to use customize rules for discovering view locations was by sub typing and changing the result of these properties. This feature work is designed towards finding a nicer way to go about this:
Proposal: View Location Expanders
- We start with a set of seed formats:
["/Views/{1}/{0}", "/Views/Shared/{0}"]
- We introduce a contract for view location expanders as
interface IViewLocationExpander
{
IEnumerable<string> ExpandViewLocations(IEnumerable<string> seed, ActionContext context);
}
- Individual expanders can add tokens, expand previously inserted tokens etc
public class LocaleViewLocationExpander : IViewLocationExpander
{
public IEnumerable<string> ExpandViewLocations(IEnumerable<string> seed, ActionContext context)
{
var locale = context.RouteData["locale"];
if (!string.IsNullOrEmpty(locale))
{
// Views/{1}/{0}.en-gb
// Views/Shared/{0}.en-us
// Views/{1}/{0}
// Views/Shared/{0}
return seed.Select(s => areaName + '/' + s)
.Concat(seed);
}
}
}
- Expanders are registered via Options so they can be re-ordered, removed etc.The
RazorViewEngine calls into these expanders to get all possible locations to locate views as part of FindView and FindPartialView.
cc @yishaigalatzer / @loudej