-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathMsScopedLifestyleManager.cs
41 lines (35 loc) · 1.13 KB
/
MsScopedLifestyleManager.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
34
35
36
37
38
39
40
41
using Castle.MicroKernel;
using Castle.MicroKernel.Context;
using Castle.MicroKernel.Lifestyle;
namespace Castle.Windsor.MsDependencyInjection
{
/// <summary>
/// Extends Windsor's <see cref="ScopedLifestyleManager"/> to work as
/// MS style scope using <see cref="MsScopedAccesor"/>.
/// </summary>
public class MsScopedLifestyleManager : ScopedLifestyleManager
{
public MsScopedLifestyleManager()
: base(new MsScopedAccesor())
{
}
public override object Resolve(CreationContext context, IReleasePolicy releasePolicy)
{
var currentScope = MsLifetimeScope.Current;
if (currentScope == null)
{
//Act as transient!
var burden = CreateInstance(context, false);
if (!releasePolicy.HasTrack(burden.Instance))
{
Track(burden, releasePolicy);
}
return burden.Instance;
}
lock (currentScope)
{
return base.Resolve(context, releasePolicy);
}
}
}
}