Skip to content

Commit

Permalink
Reuse the same DistributedContext more often. (#13221)
Browse files Browse the repository at this point in the history
  • Loading branch information
jtkech authored Feb 16, 2023
1 parent b9e02bc commit 6d95583
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public PlaceHolder()
_released = true;
_disposed = true;
}

public bool PreCreated { get; init; }
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ public static async Task<ShellContext> CreateMaximumContextAsync(this IShellCont
public static Task<ShellContext> CreateMinimumContextAsync(this IShellContextFactory shellContextFactory, ShellSettings shellSettings) =>
shellContextFactory.CreateDescribedContextAsync(shellSettings, new ShellDescriptor());

private static async Task<ShellDescriptor> GetShellDescriptorAsync(this IShellContextFactory shellContextFactory, ShellSettings shellSettings)
/// <summary>
/// Gets the shell descriptor from the store.
/// </summary>
public static async Task<ShellDescriptor> GetShellDescriptorAsync(this IShellContextFactory shellContextFactory, ShellSettings shellSettings)
{
ShellDescriptor shellDescriptor = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ async Task<ShellContext> IShellContextFactory.CreateShellContextAsync(ShellSetti
_logger.LogInformation("Creating shell context for tenant '{TenantName}'", settings.Name);
}

var describedContext = await CreateDescribedContextAsync(settings, MinimumShellDescriptor());
var describedContext = await CreateDescribedContextAsync(settings, new ShellDescriptor());

ShellDescriptor currentDescriptor = null;
await describedContext.CreateScope().UsingServiceScopeAsync(async scope =>
Expand All @@ -52,13 +52,13 @@ await describedContext.CreateScope().UsingServiceScopeAsync(async scope =>
return describedContext;
}

// TODO: This should be provided by a ISetupService that returns a set of ShellFeature instances.
Task<ShellContext> IShellContextFactory.CreateSetupContextAsync(ShellSettings settings)
{
if (_logger.IsEnabled(LogLevel.Debug))
{
_logger.LogDebug("No shell settings available. Creating shell context for setup");
}

var descriptor = MinimumShellDescriptor();

return CreateDescribedContextAsync(settings, descriptor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public DistributedContext(ShellContext context)
DistributedCache = distributedCache;
}

public ShellContext Context => _context;

public IDistributedCache DistributedCache { get; }

public DistributedContext Acquire()
Expand Down
Loading

0 comments on commit 6d95583

Please sign in to comment.