Add domain to route

Is there a way to add domains to routes, static and dynamically?

e.g. rather than

[Route("/test", “GET”)]
public class TestRequest

something like

[Route("/test", “GET”, “”)]
public class TestRequest

This route would then only apply for that domain.

Could this also be done dynamically using the API?

No there’s no domain-scoped configuration or domain-specific behavior in ServiceStack.

You would need to look into base.Request to determine the domain than handle different behavior in your Service, e.g. you can use ResolveService<T> inside your Service impl to invoke different Services.

Or depending on your solution, my preferred strategy would instead just have different instances of the same ServiceStack solution deployed in separate Web Applications with a App Config setting to determine which domain the Web App is for.

Now that I think of it you could also use a Request Converter to return a different Request DTO that ServiceStack should execute instead.

Thanks. I’ll look more into Request Converters.

We run a platform that provides websites for users, and so have thousands of domains, as well as our own admin and API domains. So while an app instance per domain won’t work, they are grouped into domain apps.

I was curious if I’d missed this as a feature, or if it was planned, before we push our current solution.

No it’s not a planned feature or something that would be a candidate to complicate routing with.

If you plan to support thousands of domains I’d treat it like data, e.g. a data attribute of a Request DTO instead of maintain separate domain-specific services.