Book Image

Mastering ServiceStack

By : Andreas Niedermair
Book Image

Mastering ServiceStack

By: Andreas Niedermair

Overview of this book

Table of Contents (13 chapters)

Registering new services and endpoints


Apart from the registration of filters, you can also add services to any application host by simply calling RegisterService on the provided host object.

To show you a real life scenario, we will implement a plugin that restricts the throughput of your services. This plugin will also register a service that we can use to inspect the current throughput of the service.

We will start off with the creation of an attribute to define the maximum throughput of an operation.

using System;
using ServiceStack;

public class ThrottleRestrictionAttribute : Attribute
{
  public const string MinuteAbbreviation = "m";
  public const string HourAbbreviation = "h";
  public const string DayAbbreviation = "d";

  public int PerMinute { get; set; }
  public int PerHour { get; set; }
  public int PerDay { get; set; }

  public int GetMaximum(string durationAbbreviation)
  {
    switch (durationAbbreviation)
    {
      case MinuteAbbreviation:
        return this.PerMinute...