NancyFx / Nancy

Lightweight, low-ceremony, framework for building HTTP based services on .Net and Mono
http://nancyfx.org
MIT License
7.15k stars 1.46k forks source link

Caching Views is not disabled in Debug Mode by default in Nancy 2.0.0-alpha #2432

Open 8 opened 8 years ago

8 commented 8 years ago

Prerequisites

In nancy 2.0.0-alpha caching razor views is not disabled by default anymore as it used to be in debug mode.

Steps to Reproduce

  1. Start nancy in debug mode
  2. Visit an url and let nancy serve a .cshtml view
  3. Modify & Save the .cshtml file
  4. Refresh your browser
  5. Notice that changes are not shown.

    System Configuration

    • Nancy version: 2.0.0-alpha
    • Nancy host
    • [x] ASP.NET
    • [ ] OWIN
    • [ ] Self-Hosted
    • [ ] Other:
    • Other Nancy packages and versions:
    • Nancy.Hosting.Aspnet
    • Nancy.ViewEngines.Razor
    • Environment (Operating system, version and so on): Win10, IISExpress
    • .NET Framework version: 4.5
    • Additional information:

Workaround:

Configure nancy yourself to disable the cache in debug mode, for example:

public override void Configure(INancyEnvironment environment)
{
    base.Configure(environment);

#if DEBUG
    environment.Views(runtimeViewUpdates: true);
#endif
}

Take care, Martin

jchannon commented 8 years ago

I wonder if we could use this https://github.com/NancyFx/Nancy/blob/feb8a122d8173eafde87bbd650faa2b04429131a/src/Nancy/DefaultRuntimeEnvironmentInformation.cs#L27 in the ViewConfiguration.Default ?

thecodejunkie commented 8 years ago

If I recall, the DefaultViewConfigurationProvider used to have the behavior of using the IRuntimeEnvironmentInformation but we changed it before we merged the pull-request. I cannot remember why we removed it, but I do know that the IRuntimeEnvironmentInformation interface was discussed in the CoreCLR context because we could no longer check the attributes.

Maybe we could update the DefaultViewConfigurationProvider to make use of #if DEBUG instead. The problem with that is that it would only function inside the debugger (I think) and not when you build and deploy your site in debug mode.

ping @NancyFx/most-valued-minions

thecodejunkie commented 8 years ago

Actually #if DEBUG would be fine for the DefaultViewConfigurationProvider. If you care either way about the behavior then you would explicitly set it and user set values always take precedence over what the default provider configures

jchannon commented 8 years ago

Bingo

On Wednesday, 27 April 2016, Andreas Håkansson notifications@github.com wrote:

Actually #if DEBUG would be fine for the DefaultViewConfigurationProvider. If you care either way about the behavior then you would explicitly set it and user set values always take precedence over what the default provider configures

— You are receiving this because you commented. Reply to this email directly or view it on GitHub https://github.com/NancyFx/Nancy/issues/2432#issuecomment-215189437

thecopy commented 7 years ago

Creating a custom ViewConfigurationProvider with return new ViewConfiguration(true,true); does not work (even though it is being hit if i set a breakpoint). Overriding Configure in bootstrapper and calling environment.Views(runtimeViewUpdates: true); fixes this problem.

2.0-b