Book Image

Mastering ServiceStack

By : Andreas Niedermair
Book Image

Mastering ServiceStack

By: Andreas Niedermair

Overview of this book

Table of Contents (13 chapters)

Chapter 1. Distributed Systems and How ServiceStack Jumps in

ServiceStack is a powerful web service framework and it offers many possibilities. ServiceStack's adaptive nature makes the components of the framework fine-grained, which makes it crucial to understand the layout and its components:

  • ServiceStack: Lets you create your own service endpoint.

  • ServiceStack.Interfaces: It holds all the base interfaces that are used for the dependency injection-driven internals of ServiceStack. You can fully customize ServiceStack by implementing and registering one of these interfaces.

  • ServiceStack.Text: In this namespace reside various serialization utilities for JSON, JSV, and CSV. It also offers dynamic JSON processing, diagnostic extensions for printing a formatted dump of an object, URL extensions to deal with the common issues, such as encoding and decoding, stream extensions, and many more.

  • ServiceStack.Client: It contains the relevant clients to connect and consume JSON, XML, JSV, SOAP, and MQ services.

  • ServiceStack.Caching: It holds provider-specific endpoints that can be injected as caching storage (InMemory, Redis, Aws, Azure, Memcached, OrmLite …).

  • ServiceStack.OrmLite: It contains a fast micro-ORM with adapters for popular RDMBS, such as the SQL Server, MySQL, PostgreSQL, SQLite, and many others.

  • ServiceStack.Redis: It holds .NET's leading client for Redis, an open source and advanced key-value store.

  • ServiceStack.Authentication: It provides various authentication providers, such as OAuth, OAuth2, OpenID, in combination with its storage providers, such as OrmLite and NHibernate.

  • ServiceStack.Logging: This includes adapters for many logging frameworks such as Elmah, NLog, Log4Net, and EventLog to provide an interchangeable and loosely coupled logging experience.

  • ServiceStack.Razor: It lets you add a Razor view engine to your web service to provide a single stack implementation of your service and front-end.

  • Various other components, such as extensions to formats (ServiceStack.MsgPack and ServiceStack.Protobuf), web service client frameworks, such as ServiceStack.Api.Swagger, a bundler for web resources (ServiceStack.Bundler), a compiler for cross-platform native Desktop applications (ServiceStack.Gap), and many others.

Note

As the NuGet package names often do not match the namespaces within, the NuGet package names are mentioned separately.

Additionally, ServiceStack offers tools that are focused on simplicity and performance, so (development-) time can be spent on a hassle-free usage. This feature makes it a great alternative to Windows Communication Framework (WCF) and others.

Note

Note that some components are dependency free, such as ServiceStack.Text and ServiceStack.Client, which do not call for a coupled usage with ServiceStack.

One of the big ideas behind ServiceStack is the Code-First approach. Before you start to design your database, you should focus on the domain design and its Plain Old CLR Objects (POCOs), which then can be used through the components of your stack:

  • In Request and Response DTOs

  • In client projects by leveraging a shared assembly

  • As data models in your database

  • As entities in your cache and session

  • In serializers and configurations

Tip

If you ever find the need to apply ServiceStack to an existing database, it will be trivial to derive your POCOs from the database schema, especially, if you are dealing with a large pre-existing database and coupled usage in the codebase. Therefore, you can use T4 scripts that are bundled with ServiceStack.OrmLite, to code-gen your POCOs. You can find these at https://github.com/ServiceStack/ServiceStack.OrmLite/tree/master/src/T4.