ServiceStack: Adding routes dynamically

你。 提交于 2019-12-04 08:27:40

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());
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!