-
Notifications
You must be signed in to change notification settings - Fork 31
Closed
Description
Func<T> and other wrappers should carry the locate key through the request. This test should pass when finished. Relates to issue #98
public class FuncFactoryClass
{
private Func<DisposableService> _func;
public FuncFactoryClass(Func<DisposableService> func)
{
_func = func;
}
public DisposableService CreateService()
{
return _func();
}
}
[Fact]
public void Keyed_Factory_And_NonKeyed_With_Different_Lifestyle()
{
var container = new DependencyInjectionContainer();
container.Configure(c =>
{
c.Export<DisposableService>().Lifestyle.SingletonPerNamedScope("CustomScopeName");
c.Export<DisposableService>().AsKeyed<DisposableService>("TransientKey").ExternallyOwned();
c.Export<FuncFactoryClass>().WithCtorParam<Func<DisposableService>>().LocateWithKey("TransientKey");
});
bool disposedService = false;
bool disposedTransient = false;
using (var scope = container.BeginLifetimeScope("CustomScopeName"))
{
var service = scope.Locate<DisposableService>();
Assert.Same(service, scope.Locate<DisposableService>());
service.Disposing += (sender, args) => disposedService = true;
var factory = scope.Locate<FuncFactoryClass>();
var transientService = factory.CreateService();
Assert.NotSame(service, transientService);
transientService.Disposing += (sender, args) => disposedTransient = true;
}
Assert.True(disposedService);
Assert.False(disposedTransient);
}