Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reuse the same DistributedContext more often. #13221

Merged
merged 15 commits into from
Feb 16, 2023
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