Skip to content

Instantly share code, notes, and snippets.

@gimmi
Created September 17, 2011 08:00
Show Gist options
  • Save gimmi/1223741 to your computer and use it in GitHub Desktop.
Save gimmi/1223741 to your computer and use it in GitHub Desktop.
Windsor 3 scoped disposing
[Test]
public void Should_resolve_lazy_components()
{
var container = new WindsorContainer();
container.Register(Component.For<LazyOfTComponentLoader>());
container.Register(Component.For<A>().LifeStyle.Transient);
var a = container.Resolve<A>(); // Ok
var lazyA = container.Resolve<Lazy<A>>(); // Fail
}
public class A
{
}
[Test]
public void Should_release_scoped_component_when_scope_is_disposed2()
{
var container = new WindsorContainer();
container.Register(Component.For<A>().LifestyleScoped());
A a;
using(container.BeginScope())
{
a = container.Resolve<A>();
}
Assert.IsTrue(a.Disposed);
}
public class A : IDisposable
{
public bool Disposed;
public void Dispose()
{
Disposed = true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment