Skip to content

Instantly share code, notes, and snippets.

@grumpydev
Last active December 10, 2015 19:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save grumpydev/4484587 to your computer and use it in GitHub Desktop.
Save grumpydev/4484587 to your computer and use it in GitHub Desktop.
Testing per request view cache implementation
In ConfigureRequestContainer:
#ifdef DEBUG
context.Items["DebugViewCache"] = existingContainer.Resolve<IViewCache>();
#endif
public class TestRenderContextFactory : IRenderContextFactory
{
private IViewResolver viewResolver;
private IViewCache viewCache;
public TestRenderContextFactory(IViewResolver viewResolver, IViewCache viewCache)
{
this.viewResolver = viewResolver;
this.viewCache = viewCache;
}
public IRenderContext GetRenderContext(ViewLocationContext viewLocationContext)
{
return new DefaultRenderContext(
this.viewResolver,
viewLocationContext.Context.Items.ContainsKey("DebugViewCache") ?
viewLocationContext.Context.Items["DebugViewCache"] as IViewCache :
this.viewCache,
viewLocationContext);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment