This repository has been archived by the owner. It is now read-only.

Allow a way to modify locations in which views are looked for without having to modify ViewEngine #1039

Closed
pranavkm opened this Issue Aug 19, 2014 · 2 comments

Comments

Projects
None yet
3 participants
@pranavkm
Copy link
Member

pranavkm commented Aug 19, 2014

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

  1. We start with a set of seed formats: ["/Views/{1}/{0}", "/Views/Shared/{0}"]
  2. We introduce a contract for view location expanders as
interface IViewLocationExpander
{
     IEnumerable<string> ExpandViewLocations(IEnumerable<string> seed, ActionContext context);
}
  1. 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);
        }
     }
 }
  1. 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

@pranavkm pranavkm changed the title Allow a view to modify locations in which views are looked for without having to modify ViewEngine Allow a way to modify locations in which views are looked for without having to modify ViewEngine Aug 19, 2014

@yishaigalatzer

This comment has been minimized.

Copy link
Contributor

yishaigalatzer commented Aug 19, 2014

Also:

  1. Seed formats can be changed.
  2. We need to decide what default expanders to build
  3. What default expanders to register
  4. Is registration indeed in Options or directly on the RazorViewEngine?
@yishaigalatzer

This comment has been minimized.

Copy link
Contributor

yishaigalatzer commented Aug 19, 2014

@pranavkm please set up a design meeting for this.

@danroth27 danroth27 added 1 - Ready and removed needs design labels Aug 22, 2014

@danroth27 danroth27 added this to the 6.0.0-alpha4 milestone Aug 22, 2014

pranavkm added a commit that referenced this issue Sep 5, 2014

pranavkm added a commit that referenced this issue Sep 5, 2014

pranavkm added a commit that referenced this issue Sep 5, 2014

pranavkm added a commit that referenced this issue Sep 19, 2014

pranavkm added a commit that referenced this issue Sep 19, 2014

@danroth27 danroth27 modified the milestones: 6.0.0-alpha4, 6.0.0-beta1 Sep 24, 2014

pranavkm added a commit that referenced this issue Sep 30, 2014

@pranavkm pranavkm closed this in ad8ab4b Oct 1, 2014

@pranavkm pranavkm added 3 - Done and removed 2 - Working labels Oct 1, 2014

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.