-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathScopeCleanupFilter.cs
33 lines (29 loc) · 1.04 KB
/
ScopeCleanupFilter.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
using Microsoft.Azure.WebJobs.Host;
using System;
using System.Threading;
using System.Threading.Tasks;
namespace DependencyInjector.AzureFunction
{
internal class ScopeCleanupFilter : IFunctionInvocationFilter, IFunctionExceptionFilter
{
public Task OnExceptionAsync(FunctionExceptionContext exceptionContext, CancellationToken cancellationToken)
{
RemoveScope(exceptionContext.FunctionInstanceId);
return Task.CompletedTask;
}
public Task OnExecutedAsync(FunctionExecutedContext executedContext, CancellationToken cancellationToken)
{
RemoveScope(executedContext.FunctionInstanceId);
return Task.CompletedTask;
}
public Task OnExecutingAsync(FunctionExecutingContext executingContext, CancellationToken cancellationToken) =>
Task.CompletedTask;
private void RemoveScope(Guid id)
{
if (IoC.Scopes.TryRemove(id, out var scope))
{
scope.Dispose();
}
}
}
}