Forked from alexandrnikitin/Stackoverflow_24762539
Last active
August 29, 2015 14:04
-
-
Save beyond-code-github/d2f795b0ab61eaa50174 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Autofac; | |
using Xunit; | |
namespace LifetimeScope | |
{ | |
public class Stackoverflow24762539 | |
{ | |
[Fact] | |
public void Repro() | |
{ | |
var builder = new ContainerBuilder(); | |
builder.RegisterType<UnitOfWork>().As<IUnitOfWork>().InstancePerLifetimeScope(); | |
using (var container = builder.Build()) | |
{ | |
using (var lifetimeScope = container.BeginLifetimeScope(b => b.RegisterInstance(new PrincipalFactory()).As<IPrincipalFactory>())) | |
{ | |
var unitOfWork = lifetimeScope.Resolve<Responder>(); | |
Assert.NotNull(unitOfWork); | |
} | |
} | |
} | |
} | |
public class Responder | |
{ | |
private IUnitOfWork unitOfWork; | |
public Responder(IUnitOfWork unitOfWork) | |
{ | |
this.unitOfWork = unitOfWork; | |
} | |
} | |
public interface IUnitOfWork | |
{ | |
} | |
public class UnitOfWork : IUnitOfWork | |
{ | |
private readonly IPrincipalFactory _principalFactory; | |
public UnitOfWork(IPrincipalFactory principalFactory) | |
{ | |
_principalFactory = principalFactory; | |
} | |
} | |
public interface IPrincipalFactory | |
{ | |
} | |
public class PrincipalFactory : IPrincipalFactory | |
{ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment