Вопрос

I've got an API project hosted in ServiceStack (3.9), and I've added a /docs folder containing two Razor files, _layout.cshtml and default.cshtml

I have configured no caching; my AppHost class looks like this:

public class AppHost : AppHostBase {
    public AppHost() 
        : base("My API", typeof(UserService).Assembly, typeof(GetUserDto).Assembly) {
    }

    public override void Configure(Container container) {
        ServiceExceptionHandler += 
            (req, request, exception) => {
                Elmah.ErrorSignal.FromCurrentContext().Raise(exception);
                return DtoUtils.HandleException(this, request, exception);
            };

        JsConfig.EmitCamelCaseNames = true;
        Plugins.Add(new RazorFormat());
        Plugins.Add(new SwaggerFeature());
    }

    public static void Start() {
        new AppHost().Init();
    }
}

My Razor pages are working fine - going to localhost/api/docs shows the default page and uses the supplied layout - but if I make a change to the Razor code, I need to recompile the app before it's visible in a browser.

My understanding was that ServiceStack views worked like ASP.NET MVC views - they're interpreted at request time, and any changes to the view code show up immediately, and if you want to cache your rendered views you'll need to configure that explicitly. Have I missed a config setting, or is there something else I need to do to get ServiceStack pages to recompile without needing to rebuild the project?

Это было полезно?

Решение

You need to set the AppHost config to debug mode:

SetConfig(new EndpointHostConfig {
    DebugMode = true,
});

For performance reasons changes are only monitored for in Debug mode. See here for more information.

Automatic reload of modified views, layout templates and partials (in Debug mode)

The best way to avoid the Start-Up penalty is to avoid having to restart the AppDomain in the first place. So in Debug Mode we'll also do this where a background file system watcher monitors all pages, partials and Layout templates for modifications and recompiles and auto-reloads them on the fly, all-ready to deliever instant response time once the page is requested.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top