Helped me a lot when I did a project with multiple tenants.
Link: https://msdn.microsoft.com/en-us/library/aa479086.aspx