ThatRendle / Simple.Web

A lightweight, object-oriented (Model-View-Handler) framework for modern web development in .NET.
MIT License
231 stars 66 forks source link

If Views are in a different project than the hosting class the views won't be found #93

Open mastoj opened 10 years ago

mastoj commented 10 years ago

I have a sample project showing the problem: https://github.com/mastoj/NestDemo/tree/DecoupleHosting

I am doing self hosting in two different ways. First I had it in the NestDemo project, but than I wanted to decouple hosting from application and tried to put the hosting in a separate project, NestDemo.SelfHost. That didn't work since AssemblyAppRoot in RazorViews removes the bin/debug part of the file path which is needed I think if you have the hosting and application separated.

ianbattersby commented 10 years ago

Well spotted! That would indeed be a problem if your views are separate from hosting.

There are obviously many ways to skin this cat, thoughts include;

  1. Some syntax in "ViewPath:Value" to denote absolute path (would this work for you?)
  2. Use the "ViewPath:Value" value to define a relative path (e.g. "../../MyViewsAssembly/Views")
  3. Allow override of AppRoot through Simple.Web.Configuration

Thoughts @markrendle?

mastoj commented 10 years ago

One more remark. I'm not sure if my description is complete. I tried copying the application to a path that didn't include bin or debug, but that didn't help either which I thought would fix the problem. I might have done something wrong when I did the test since I only had one minute this morning.

To your suggestion, 1. could work for simple scenarios but that means you are tightly coupled to the hosting environment in a way. I think override of AppRoot is the best solution.

However, there is an additional problem with this scenario and that is during development. It might be harder to keep update the view when developing, but that might be solvable with setting the "ViewPath:Value" to a relative path during development.