forked from dotnetcore/AspectCore-Framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScopeAspectContextFactory.cs
More file actions
34 lines (30 loc) · 1.25 KB
/
Copy pathScopeAspectContextFactory.cs
File metadata and controls
34 lines (30 loc) · 1.25 KB
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
34
using System;
using AspectCore.DynamicProxy;
namespace AspectCore.Extensions.AspectScope
{
[NonAspect]
public sealed class ScopeAspectContextFactory : IAspectContextFactory
{
private readonly IAspectScheduler _aspectScheduler;
private readonly AspectContextFactory _aspectContextFactory;
public ScopeAspectContextFactory(IServiceProvider serviceProvider, IAspectScheduler aspectContextScheduler)
{
_aspectScheduler = aspectContextScheduler ?? throw new ArgumentNullException(nameof(aspectContextScheduler));
_aspectContextFactory = new AspectContextFactory(serviceProvider);
}
public AspectContext CreateContext(AspectActivatorContext activatorContext)
{
var aspectContext = _aspectContextFactory.CreateContext(activatorContext);
if (!_aspectScheduler.TryEnter(aspectContext))
{
throw new InvalidOperationException("Error occurred in the schedule AspectContext.");
}
return aspectContext;
}
public void ReleaseContext(AspectContext aspectContext)
{
_aspectContextFactory.ReleaseContext(aspectContext);
_aspectScheduler.Release(aspectContext);
}
}
}