Skip to content

Commit

Permalink
One test to go
Browse files Browse the repository at this point in the history
  • Loading branch information
ENikS committed Jan 6, 2018
1 parent 81f5bda commit f30ff94
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/Lifetime/LifetimeManagerFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace Unity.Lifetime
public class LifetimeManagerFactory : ILifetimeFactoryPolicy
{
private readonly ExtensionContext _containerContext;
private readonly ILifetimeFactoryPolicy _policy;

/// <summary>
/// Create a new <see cref="LifetimeManagerFactory"/> that will
Expand All @@ -27,12 +28,36 @@ public LifetimeManagerFactory(ExtensionContext containerContext, Type lifetimeTy
LifetimeType = lifetimeType;
}

/// <summary>
/// Create a new <see cref="LifetimeManagerFactory"/> that will
/// return instances of the given type, creating them by
/// resolving through the container.
/// </summary>
/// <param name="policy">LifetimeManager to create.</param>
public LifetimeManagerFactory(ExtensionContext containerContext, ILifetimeFactoryPolicy policy)
{
_containerContext = containerContext;
_policy = policy ?? throw new ArgumentNullException(nameof(policy));
LifetimeType = policy.GetType();
}


/// <summary>
/// Create a new instance of <see cref="ILifetimePolicy"/>.
/// </summary>
/// <returns>The new instance.</returns>
public ILifetimePolicy CreateLifetimePolicy()
{
if (null != _policy)
{
var policy = _policy.CreateLifetimePolicy();
if (policy is IDisposable)
{
_containerContext.Lifetime.Add(policy);
}
return policy;
}

var lifetime = typeof(TransientLifetimeManager) == LifetimeType
? new TransientLifetimeManager()
: (LifetimeManager)_containerContext.Container.Resolve(LifetimeType, null);
Expand Down

0 comments on commit f30ff94

Please sign in to comment.