public override async Task Invoke(IOwinContext context) { TenantContext tenantContext = context.GetTenantContext(); if (tenantContext == null || tenantContext.IsEmpty()) { await this.Next.Invoke(context); return; } Lazy <Func <IDictionary <string, object>, Task> > branch = branches.GetOrAdd(tenantContext, new Lazy <Func <IDictionary <string, object>, Task> >(() => { IAppBuilder newAppBuilderBranch = rootApp.New(); newBranchAppConfig(tenantContext, newAppBuilderBranch); newAppBuilderBranch.Run((oc) => this.Next.Invoke(oc)); return(newAppBuilderBranch.Build()); })); await branch.Value(context.Environment); }