This project is read-only.

support for multiple view dlls

Jan 29, 2013 at 11:11 AM

I'm trying to write a multi-tenated razor view engine using the razorgenerator.mvc library, where depending on a value specified in the route a different assembly will be used to lookup views.

So far I've converted the constructor to take an IEnumerable<Assembly> and made adjustments in the RazorViewEngine to accomodate this.

I'm up to the PrecompiledViewLocationCache and trying to figure out how I can have it map to multiple assemblies, I'm not quite sure how to get this working as the constructor only accepts one assembly and it seems like after this there isnt enough information to determine what assemblyname to use in the key.

I'm wondering going even further if this is even possible, is there any other sticking points I might run into?

Jan 29, 2013 at 5:05 PM
Edited Jan 29, 2013 at 5:06 PM

You could in theory create an engine for each of those assemblies and insert them in to the thing (correspondingly a VirtualPathProvider too). This would be closer to the behavior you'd get today if you have multiple precompiled areas referenced in your project. 

Ignore the user name :)

Jan 30, 2013 at 3:52 AM

Yeah I thought about it last night more and Im thinking somewhat along those lines.

 

Going to try creating a MultiTenatedViewEngine that has a collection of view engines inside it and manage it that way, all the settings for the view engines will be the same itl just be the assembly that they resolve views in that will be different.

Jun 7, 2013 at 8:55 AM
There are some problems with multi-tenated engines and areas. Consider the following project structure:
- CommonWeb 
--- Areas 
----- Admin 
------- Controllers 
--------- HomeController.cs (Index action) 
------- Views 
--------- Home 
----------- Index.cshtml 
- Web 
--- Controllers 
----- HomeController.cs (Index action) 
--- Views 
----- Home 
------- Index.cshtml
and engines registration code:
ViewEngines.Engines.Insert(0, commonEngine); 
ViewEngines.Engines.Insert(0, engine); /* The order is important */
If you request Admin/Home/Index action, you'll receive contents of the "Web/Views/Home/Index.cshtml" file, because of VirtualPathProviderViewEngine.GetPath method implementation. On the other hand, the problem of finding the needed compiled view lies with the engine itself, not the MVC engine subsystem.

So, it is important to have one engine that has one big hash table with all the views registered from multiple assemblies. You can try CompositePrecompiledMvcEngine from RazorGenerator.Mvc 2.1.0.
Coordinator
Jun 7, 2013 at 3:13 PM
@odinserj: would you have any comments on this related thread? In that case, it's about a PrecompiledEngine vs the default engine.