I am looking for an example implementation for resolving tenants in a multi-tenant ServiceStack API layer.
Asked
Active
Viewed 305 times
0
-
1did you looked here: http://stackoverflow.com/questions/18206488/multi-tenant-servicestack-api-same-deployment-to-respond-to-requests-on-differe? – Prashant Lakhlani Dec 03 '13 at 06:23
-
I did but with no acceptance on answer was hoping for a more concrete approach or community accepted best practice for setting up tenant resolution in a service stack API request – Ryan Fisch Dec 03 '13 at 06:34
-
Another approach is to create a request filter and set appropriate properties in HttpContext.Current.Items that can be used inside service. I don't see anything related to this in service stack wiki. that means there is no proven best practices defined yet. I am also planning to implement something similar and following these kind of questions around various forums. Try servicestack google group. – Prashant Lakhlani Dec 03 '13 at 07:03
1 Answers
1
If you've got your Api host setup and you've providing an implementation of AppHostBase, you can override the Configure method like so;
public class ApiHost : AppHostBase
{
public ApiHost() : base("Service Name", typeof(ApiHost).Assembly) { }
public override void Configure(Funq.Container container)
{
//resolve your tenant here..
}
}
Now you probably want some code to resolve your tenant. Say you were doing this via subdomain, you want something like this;
string subdomain = HttpContext.Current.Request.Url.Host.Split('.')[0].ToLower();
You should probably perform some checks to ensure validity of the url too. Then just use your repository or DAL to resolve your tenant with a relevant query.
After that you need to decide how you're going to pass your tenant about to your services and such. Question for another time, probably :)

PaulB
- 962
- 7
- 15