AsyncServiceScope
An IServiceScope implementation that implements IAsyncDisposable.
using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
namespace Microsoft.Extensions.DependencyInjection
{
[DebuggerDisplay("{ServiceProvider,nq}")]
public readonly struct AsyncServiceScope : IServiceScope, IDisposable, IAsyncDisposable
{
private readonly IServiceScope _serviceScope;
[System.Runtime.CompilerServices.Nullable(1)]
public IServiceProvider ServiceProvider {
[System.Runtime.CompilerServices.NullableContext(1)]
get {
return _serviceScope.ServiceProvider;
}
}
[System.Runtime.CompilerServices.NullableContext(1)]
public AsyncServiceScope(IServiceScope serviceScope)
{
System.ThrowHelper.ThrowIfNull(serviceScope, "serviceScope");
_serviceScope = serviceScope;
}
public void Dispose()
{
_serviceScope.Dispose();
}
public ValueTask DisposeAsync()
{
IAsyncDisposable asyncDisposable = _serviceScope as IAsyncDisposable;
if (asyncDisposable != null)
return asyncDisposable.DisposeAsync();
_serviceScope.Dispose();
return default(ValueTask);
}
}
}