⚠ This page is served via a proxy. Original site: https://github.com
This service does not collect credentials or authentication data.
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Immediate.Cache.Shared/ApplicationCacheBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,11 @@ private async Task RunHandler(CancellationTokenSource tokenSource)
try
{
var token = tokenSource.Token;
var scope = handler.GetScope();
var scope = handler.GetScope(out var service);

await using (scope.ConfigureAwait(false))
{
var response = await scope.Service
var response = await service
.HandleAsync(
request,
token
Expand Down
28 changes: 23 additions & 5 deletions src/Immediate.Cache.Shared/Owned.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,30 @@ IServiceScopeFactory serviceScopeFactory
/// An <see cref="OwnedScope{T}"/> containing both the scope and the service, so that the scope can be disposed
/// at the appropriate time.
/// </returns>
public OwnedScope<T> GetScope()
public OwnedScope<T> GetScope() => GetScope(out _);

/// <summary>
/// Creates a temporary scope and gets an instance of the service from that scope.
/// </summary>
/// <param name="service">
/// The instance of the service created from the scope.
/// </param>
/// <returns>
/// An <see cref="OwnedScope{T}"/> containing both the scope and the service, so that the scope can be disposed
/// at the appropriate time.
/// </returns>
public OwnedScope<T> GetScope(out T service)
{
var scope = serviceScopeFactory.CreateAsyncScope();
return new(
scope.ServiceProvider.GetRequiredService<T>(),
scope
);
try
{
service = scope.ServiceProvider.GetRequiredService<T>();
return new(service, scope);
}
catch
{
scope.Dispose();
throw;
}
}
}
Loading