Getting started with ServiceStack and Razor templates
Getting ready
Before we can work with Razor in ServiceStack, we need to install the servicestack.razor
NuGet package, as follows:
PM> Install-Package ServiceStack.Razor
Package Manager will then copy the relevant plugin components and add references for us.
How to do it…
We'll start with the basic
HelloWorldService
and build it up adding the Razor bits. Before we are able to work with Razor in our project, of course, we'll also need to add the Razor plugin in theConfigure
method ofAppHost
:public class ApplicationHost : AppHostBase { public ApplicationHost() : base("Greeting Service", typeof (GreetingService).Assembly) { } public override void Configure(Funq.Container container) { Plugins.Add(new RazorFormat()); } }
Then, we'll decorate our service with an annotation saying that we'd like ServiceStack to render a specific method for the view that will be created shortly, as follows:
public class GreetingService : Service...