In this tutorial, you will learn how Episerver hooks into the normal MVC rendering pipeline in order to map a page request to a page within Episerver.
The main difference between Episerver and MVC are how incoming requests are managed. In an Episerver website, an incoming request URL does not map to a specific controller/action, but rather the incoming request should point to a specific page type stored within the Episerver database.
When a request comes in, Episerver needs to get the request, find the appropriate page from the database and then based on that page-type, find the correct controller to use and, after that, it's all plain sailing and the page request is sent on its merry little way. The template resolver... if the name doesn't give it away too much, is the thing within the pipeline that its job is to find the correct template to use for a request. For example, when we create a controller:
We use the Episerver PageController, and pass in the page type we want to match on, as T. When we go down the inheritance stack, you'll see this class being inherited:
This is how Episerver magically hooks up a lot of the controllers etc.. as long as you inherit from the correct type, all the attributes and appropriate TemplateDescriptors are added for you. I've mainly used template resolvers when I've been working with partial views, or when I've enabled the display options feature to allow content editors to dynamically resize block widths.
Template Resolver Events
Episerver is very developer-friendly and one of the benefits of this is that, pretty much, everything that you may want to customize can be done fairly easily. If you create an initialization module, you can hook into the template resolver events:
In the example above, when Episerver finds an appropriate controller to use for an incoming request, it will trigger the MyEvent_TemplateResolved() method. If you want to change the controller that gets calls, add in extra data into the route value collection etc.. then this is a perfect time to add it.