antonioh
antonioh

Reputation: 2944

ASP.NET MVC Compile views in separate assemblies

I'm creating a solution where I have several projects, each of them having the responsibility of dealing with entities, MVC views and controllers of a certain kind. That is, one deals with accountance, another with company management, etc. This allows us to reuse them in multiple solutions.

I'm able to use the views in the different assemblies from the core project of the solution (a standard MVC project) by registering a VirtualPathProvider, and the trick of making the views as Embedded Resources, so they can be loaded from outside their DLL.

The main (and huge) drawback of this approach is that by setting the views as Embedded Resources takes away the possibility of compiling, using IntelliSense and debugging them, so it makes the development really tricky, and the maintenance even more so.

Is there any way to make compile this views inside DLLs? Am I missing something there or is there any other better approach to this?

Note: I can compile views in my MVC Project, but not the ones inside the DLLs.

Upvotes: 5

Views: 1021

Answers (1)

Mark Seemann
Mark Seemann

Reputation: 233125

I don't know if this helps you, but...

For a while I wanted to do the same as you until something occurred to me: As long as the views exist as .aspx and .ascx files, they can be used to 'skin' the application since they are not part of the compiled application. In other words, the benefits from having all the Views as uncompiled files in the final, composed application are just too great to ignore, IMO.

So I ended up deciding that the final, composed application is responsible for how everything is rendered. That also means that if I have two different applications that reuse the same modules, they can render these very differently.

These files should contain only rendering code anyway, so should really be developed by a HTML/Graphics designer - not a developer.

All Controllers and ViewModels I still implement in separate modules (.dlls).

Upvotes: 1

Related Questions