Guest User

Untitled

a guest
Nov 19th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. public class StartUp {
  2.  
  3. public void Configuration(IAppBuilder app) {
  4. var builder = new ContainerBuilder();
  5.  
  6. //Note: Initialize / register the Metadata Service that can bring the tenant details from the corresponding store
  7. builder.RegisterType<TenantMetadataService>().As<ITenantMetadataService>();
  8.  
  9. //Note: This helps you in accessing the TenantMetadata from any constructor going forward after the below registry
  10. builder.Register(ti => TenantMetadata.GetTenantMetadataFromRequest()).InstancePerRequest();
  11.  
  12. //TODO: Register the various services / controllers etc which may require the tenant details here
  13. }
  14.  
  15. }
  16.  
  17. public class TenantMetadata {
  18.  
  19. public Guid TenantId { get;set; }
  20. public Uri TenantUrl { get;set; }
  21. public string TenantName { get;set; }
  22.  
  23. public static TenantMetadata GetTenantMetadataFromRequest() {
  24.  
  25. var context = HttpContext.Current;
  26.  
  27. //TODO: If you have any header like TenantId coming from the request, you can read and use it
  28. var tenantIdFromRequestHeader = "";
  29.  
  30. //TODO: There will be a lazy cache that keeps building the data as new tenant's login or use the application
  31. if(TenantCache.Contains(...))return TenantCache[Key];
  32.  
  33. //TODO: Do a look-up from the above step and then construct the metadata
  34. var tenantMetadata = metadataSvc.GetTenantMetadata(...);
  35. //TODO: If the data match does not happen from the Step2, build the cache and then return the value.
  36. TenantCache.Add(key,tenantMetadata);
  37. return tenantMetadata;
  38. }
  39. }
Add Comment
Please, Sign In to add comment