17

Here is what I want to achieve, I want to separate AREAs of ASP.NET MVC as pure single DLL.

  1. Blog.DLL
  2. Forums.DLL
  3. FAQ.DLL

Each of them are individual ASP.NET MVC Area, with its own default CSHTML or ASPX pages. Installing, migrating and maintaining lots of pages including resources, javascripts and so on are real pain for long run. As most of these will hardly change.

My final website will be like this.

\MvcApplication
   \bin
      \MvcApplication.bin
      \Blog.dll
      \Forums.dll
   \Controllers
      \..
   \Models
      \..
   \Views
      \..
   \Global.asax
   \Web.config

Without adding any thing, just dropping Blog.dll, my application should support /blog and all its pages. If I want to customize something, than I can add area, and add only cshtml pages..

\MvcApplication
   \bin
      \MvcApplication.bin
      \Blog.dll
      \Forums.dll
   \Areas
      \Blog
          \Views
              \Shared
                  \BlogLayout.cshtml <-- this will override the look
   \Controllers
      \..
   \Models
      \..
   \Views
      \..
   \Global.asax
   \Web.config

This will help in reusing ASP.NET Area Plugins, by simply dropping the dll in bin folder. However web.config may require some changes, but most likely we will save configure values in database and only thing needed will be "Entity Framework connection string" in web.config.

My challenges (Questions)

  1. Is it possible? It sure looks to me, but will there be any reflection/permission issues?
  2. How do I include cshtml/aspx views within one DLL? Probably compiled versions? I have seen couple of text template based View Engines on codeplex but I am little confused on how to actually use them.
  3. And how do I get ViewEngine to first check if physical directory file exists or not and then look into cshtml/aspx within the dll itself as resource file?
tereško
  • 58,060
  • 25
  • 98
  • 150
Akash Kava
  • 39,066
  • 20
  • 121
  • 167

3 Answers3

9

You may take a look at the following article which illustrates how a custom VirtualPathProvider could be used in order to retrieve Razor views that are embedded into separate assemblies as resources.

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • What about aspx file? Mostly we only use cshtml, but for printing PDF, cshtml does not work with unknown html tags, so we use aspx sometimes. – Akash Kava Jul 14 '12 at 10:54
  • 1
    I don't know about ASPX. It's been a long time since I stopped using it. Maybe the virtual path provider could be adapted. – Darin Dimitrov Jul 14 '12 at 11:17
  • You can use EmbeddedResourceVirtualPathProvider which can be installed straight from Nuget. It works with asset files. https://github.com/mcintyre321/EmbeddedResourceVirtualPathProvider#readme – mcintyre321 Apr 06 '13 at 16:10
1

Maybe worth looking at portable areas from mvccontrib. I haven't used them since MVC 2, but found the following SO question by someone having some problems using them with MVC 3, with some possible solutions: ASP.NET MVC 3, Razor Views, and Portable Areas

Community
  • 1
  • 1
s1mm0t
  • 6,035
  • 4
  • 38
  • 45
1

MvcCodeRouting supports what you want, plus many other cool stuff. Check out this post about ASP.NET MVC Plugins.

Max Toro
  • 28,282
  • 11
  • 76
  • 114