Book Image

ServiceStack 4 Cookbook

Book Image

ServiceStack 4 Cookbook

Overview of this book

Table of Contents (18 chapters)
ServiceStack 4 Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

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…

  1. 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 the Configure method of AppHost:

    public class ApplicationHost : AppHostBase
    {
      public ApplicationHost() : base("Greeting Service", typeof (GreetingService).Assembly)
      { }
    
      public override void Configure(Funq.Container container)
      {
        Plugins.Add(new RazorFormat());
      }
    }
  2. 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...