-
Notifications
You must be signed in to change notification settings - Fork 2.1k
MVC precompilation design notes 5/12/2015 #2551
Comments
I'd like to add a few comments, some of which I didn't and some of which I did get to mention during said meeting, but didn't think I managed to explain properly. Some things are easier to do in writing without the time-constraint and added nervousness of suddenly being put in a conference call with the people who might have written most of MVC and DNX (it was great fun btw). But before I begin I feel I should say that my standpoint is one of wanting to consume precompiled views, ie. serve them to the client. How these precompiled views are generated (as long as it's not obnoxiously hard), and how the tooling and or VS deals with all of this is outside the scope of what I'm about to discuss, because I have no idea how any of that works presently, and am in no way qualified to discuss the matter. So if there is anything in what I am writing that would not work well with tooling or such, by all means please point it out. Also, in writing this, I am of the understanding that how precompiled views in Razor work today is up for discussion, and might be changed entirely. That includes how the views are precompiled, and how the are located/served by the application running, and any other aspects that deal with the idea of precompiled Razor views. Today, when you in your I suggest, that instead of having the view engine have one page factory, it can have a list of them (which can be added to or removed from by the end user application, typically during configuration of MVC and DI). One of these would be the One of the boons presented by simply having a list of page factories (even without actually adding any other kind of page factories) is the ability to add more to the list. So, for instance, if you have 3 assemblies which have embedded Secondly a second page factory should be added to MVC, something like By default, the two page factories that's used by MVC would look as following:
Let's go through some of the scenarios with this setup. For the purpose of simplifying these explanations, I'm going to assume that in all of them there are two projects, Scenario 1: Default setup, request
|
Hello @Alxandr, nice to meet you. And thanks again for the interest and participation! As always with most problems there are several solutions which can work - this is probably one of those situations where we're looking at several perfectly valid approaches to the problem and weighing them against each other. Having more than one view factory could certainly be made to work, but I'm not sure it's really necessary. It might also be true that the way precompilation is currently supported at runtime could also be simplified. I'm thinking specifically of how I've seen other view engine support pre-compilation, so as always I'm biased in that way :). I'll try to walk though how it was done. Setting aside for a moment the idea of precompilation or running without files on disk - a view engine in its default configuration has three moving parts:
Given that - precompilation was implemented without actually making the view factory itself aware of the feature at all. When the call was made to
That's all it took - the view location resolvers and view factory themselves had no idea precompilation was even a feature! When a view name was turned into a path it matched the normal file path patterns because it looked like it was present (even if it wasn't copied as a content file with the web app.) Then, when that path was instantiated, the pre-populated cache-hit meant it would use the already loaded Type. So at runtime it was literally a normal cache-hit - not a special case - the engine had no idea that the Type was precompiled view rather than a previously-compiled view. |
I just have more motivating scenarios for precompiled views: |
Something like this could be huge in terms of enabling modular web applications (i.e. dropping a "Forum" or "Blog" module into an existing MVC web application.) How difficult would it be to implement the following? Opting in to pre-compilation:In @using X
@class MyNs.LoginView (LoginViewModel model, SignInManager<ApplicationUser> signInManager)
<div>...</div> When a Returning a pre-compiled view from a controller:In public IActionResult Login
{
return new LoginView(model, signInManager);
} You may also be able to swap out the view using DI, which is really useful if you want to customize a view in a referenced assembly ("module"). Before returning the instance, you could also call methods on it and/or register event handlers to alter the text stream to be rendered (f.e. you may replace something in the HTML). Benefits:
Edit: I forgot to mention, this can be implemented without the parameter list (just |
👍 @glen-84. +1 for strongly typed views, I do hate how views are still strongly tied to their physical path. Also makes passing in the view model and other models more logical, with less magic behind the scenes. |
My requirements for precompilation fall under 2(c) above. I also agree with 3. Under 4, I am unsure of having the requirement of 4b (it seems like an implementation requirement ), but want 4c ( although I am not completely sure how this would work - I guess there are scenarios where the compilerCache entry needs to be rebuilt due to imports or global changes and having the source would allow for re-compilation ). |
@pranavkm putting this on your plate. |
If you need me to test stuff with regards to crazy things I tend to do with this stuff (like plugging F# and Razor), just let me know :) |
@Alxandr I'm sure we will 😄 |
We're done with the work per these design notes. |
Today we had a design meeting with: @Alxandr @danroth27 @DamianEdwards @davidfowl @dougbu @lodejard @pranavkm @NTaylorMullen @ToddGrun @muratg
Please add your own thoughts as comments to this thread.
Agenda
Meeting notes
a. Server optimization (especially for large sites)
b. Avoiding using a compiler on the server, which is good for security purposes
c. Components with everything compiled in (including views) and ready to go
a. All view locators would always check for a file “on disk” (whether it’s physical or virtual)
b. Precompilation would embed at least empty placeholder files into a virtual embedded file system
c. You could also have a case where you embed the full files into the embedded file system, but also have precompilation enabled. You would then have updateable precompilation.
The text was updated successfully, but these errors were encountered: