How to Establish the Proper TenantContext Within an Extension

Follow

The Apprenda Platform allows developer to access contextual information regarding the current organization (refer to the current link for more information: http://docs.apprenda.com/current/contexts). When using extensions a new TenantContext is appended to the stack for the organization that developed the extension, this means that TenantContext.Current won't retrieve the running organization but the developer of the extension instead. In order to retrieve the right information you can use the following method:

private TenantContext EstablishProperContext()
{
	if (TenantContext.Current.History.Skip(1).Any())
	{	
		/*Because this will run as a single tenant app, the top tenant context is the tenant ID for that deployed the extension application. In order to get the ID for the executing tenant, we have to move up the stack once.*/
		return TenantContext.NewTenantContext(TenantContext.Current.History.Skip(1).First().TenantId); 
	}
	else
	{
		return TenantContext.NewTenantContext(TenantContext.Current.TenantId); 
	}
}
Have more questions? Submit a request

Comments