@@ -13,6 +13,7 @@ namespace Unity.Lifetime
13
13
public class LifetimeManagerFactory : ILifetimeFactoryPolicy
14
14
{
15
15
private readonly ExtensionContext _containerContext ;
16
+ private readonly ILifetimeFactoryPolicy _policy ;
16
17
17
18
/// <summary>
18
19
/// Create a new <see cref="LifetimeManagerFactory"/> that will
@@ -27,12 +28,36 @@ public LifetimeManagerFactory(ExtensionContext containerContext, Type lifetimeTy
27
28
LifetimeType = lifetimeType ;
28
29
}
29
30
31
+ /// <summary>
32
+ /// Create a new <see cref="LifetimeManagerFactory"/> that will
33
+ /// return instances of the given type, creating them by
34
+ /// resolving through the container.
35
+ /// </summary>
36
+ /// <param name="policy">LifetimeManager to create.</param>
37
+ public LifetimeManagerFactory ( ExtensionContext containerContext , ILifetimeFactoryPolicy policy )
38
+ {
39
+ _containerContext = containerContext ;
40
+ _policy = policy ?? throw new ArgumentNullException ( nameof ( policy ) ) ;
41
+ LifetimeType = policy . GetType ( ) ;
42
+ }
43
+
44
+
30
45
/// <summary>
31
46
/// Create a new instance of <see cref="ILifetimePolicy"/>.
32
47
/// </summary>
33
48
/// <returns>The new instance.</returns>
34
49
public ILifetimePolicy CreateLifetimePolicy ( )
35
50
{
51
+ if ( null != _policy )
52
+ {
53
+ var policy = _policy . CreateLifetimePolicy ( ) ;
54
+ if ( policy is IDisposable )
55
+ {
56
+ _containerContext . Lifetime . Add ( policy ) ;
57
+ }
58
+ return policy ;
59
+ }
60
+
36
61
var lifetime = typeof ( TransientLifetimeManager ) == LifetimeType
37
62
? new TransientLifetimeManager ( )
38
63
: ( LifetimeManager ) _containerContext . Container . Resolve ( LifetimeType , null ) ;
0 commit comments