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

Created on 27 Apr 2016  Â·  5Comments  Â·  Source: NancyFx/Nancy

Prerequisites

  • [x] I have written a descriptive issue title
  • [x] I have verified that I am running the latest version of Nancy
  • [ ] I have verified if the problem exist in both DEBUG and RELEASE mode
  • [x] I have searched open and closed issues to ensure it has not already been reported

    Description

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

Most helpful comment

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

All 5 comments

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

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

Bingo

On Wednesday, 27 April 2016, Andreas HÃ¥kansson [email protected]
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

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jchannon picture jchannon  Â·  7Comments

jgillich picture jgillich  Â·  7Comments

thecodejunkie picture thecodejunkie  Â·  4Comments

Zaid-Ajaj picture Zaid-Ajaj  Â·  4Comments

Radzhab picture Radzhab  Â·  11Comments