Skip to content

Add InvalidatingCachingProvider and ResolvePathTemplateManager (ease of use and improved debugging support) #250

@axefrog

Description

@axefrog

You've got a great library here. I see there is an attempt to provide some easy methods, but I don't think they actually cover a really common use case - specify a file path and model and have RazorEngine automatically compile and cache the template and reload it if the source file changes.

Specifying the template key, deciding whether I want to Run, RunCompile or Compile, setting a template manager, reference resolver, etc. - these are all implementation details that would benefit from being buried under the hood for most people. I'm not saying don't have them as options like you do right now, but in most cases I just want to specify a file path and a model and have the thing render.

Your compilation and caching can automatically make decisions with regards to the model type that is passed in. That's another decision that you can hide from the user, because in most cases, they won't care. A few boolean option flags on the default static instance should provide most configuration decisions and can be set in a static constructor at the start.

// Make it easy to set common options
Engine.Razor.Config.ViewPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Views");
Engine.Razor.Config.EnableLayouts = true;
Engine.Razor.Config.EnableSomeOtherOption = false;

// Make it easy to render a template and not have to worry about how it's done
string html = Engine.Razor.Render("Home/Index.cshtml", new { Title = "Hello" });

I like what you've done; if you could just make the primary use case easy then it would be perfect.

p.s. While you're here - without having to make my own implementation of different things, is there a way to get it to recompile a template that is already cached? For development, I just want it to reload the template on every request, because I'm frequently updating the template, and so caching is not wanted.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions