Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ServiceStack: Adding routes dynamically

Tags:

servicestack

I have not tried this yet, but I would like each module (Silverlight) to register its own routes, rather then adding it in application start.

Can routes be added to AppHost after application start, or do they all have to be immediatelly registered during Configure step?

I am thinking to scan all assemblies at the startup and provide AppHost with all assemblies that implement service stack services, but let each module add its own routes (have not figured out yet exact mechanism.

Before I go down this route, need to know if it is possible to add routes after the Configure step.

like image 966
epitka Avatar asked Apr 26 '13 21:04

epitka


1 Answers

All configuration and registration in ServiceStack should be done within the AppHost.Configure() method and remain immutable thereafter.

If you want to encapsulate registrations of routes in a module than package it as a Plugin and register them manually on IPlugin.Register(IAppHost).

Here are some different ways to register routes:

public class MyModule : IPlugin
{
    public void Register(IAppHost appHost)
    {
        appHost.Routes.Add<MyRequestDto>("/myservice", "POST PUT");

        appHost.Routes.Add(typeof(MyRequestDto2), "/myservice2", "GET");

        appHost.RegisterService(typeof(MyService), "/myservice3"); 
    }
}

Then inside your AppHost.Configure you would register the Plugin, e.g:

Plugins.Add(new MyModule());
like image 124
mythz Avatar answered Oct 11 '22 12:10

mythz