ServiceStack Razor files in a separate project

I have a solution consisting of a backst end ServiceStack, with the usual setup (AppHost, ServiceInterface and ServiceModel), and both a winforms application and an application using iOS applications.

Now I want to create a web admin, and I'm looking for advice on how to structure this one . I would like to keep the apphost project small since SS docs say

Ideally, a root-level AppHost project should be easy and implementation free.

So, I would like to have a web admin in a separate project , with all the .cshtml and content, and all that.

Is it possible? Not recommended? Any ideas?

Some alternatives I can think of

  • single-page application, let several cshtml files are in the AppHost project. Is it worth the learning curve?
  • There is a separate project calling web services. Isn't that very inefficient considering they live on the same web server? Or should this be considered an advantage because it makes everything loosely coupled?
+1
architecture servicestack servicestack-razor
source share
2 answers

Look at the docs using the Razor Compiled Views and ServiceStack.Gap GitHub Repository on how to create ServiceStack inline solutions that use Razor compiled views.

+1
source share

I would like to provide a more complete answer for beginners:

  • The design for the website must be included with a razor. For example, it should have a link to ServiceStack.Razor , so .cshtml will compile.

  • As @mythz pointed out, add ServiceStack.Razor.BuildTask to precompile the razor files. This is necessary to include the LoadFromAssemblies parameter in them LoadFromAssemblies

  • In the main AppHost, specify that Razor files can be found in another assembly using LoadFromAssemblies for example:

      this.Plugins.Add(new RazorFormat { LoadFromAssemblies = { typeof(ActivityServer.Admin.AdminServices).Assembly } }); 
  • So far, everything has been connected with the Razor.cshtml files. Also include services, for example. for more complex views, just add this to AppHost() : base(...) , or if you want the service prefix to use AppHost.RegisterService.

It should be noted that in the external DLL there is no separate namespace for Razor files, therefore, in the external DLL file "hello.cshtml" the file with the same name is encountered in the main AppHost. Putting all cshtml files (in an external dll) under a subfolder will help, because the folder will be part of the URL.

+1
source share

All Articles