Skip to content

Instantly share code, notes, and snippets.

@kkozmic
Created December 31, 2009 07:49
Show Gist options
  • Save kkozmic/266661 to your computer and use it in GitHub Desktop.
Save kkozmic/266661 to your computer and use it in GitHub Desktop.
namespace ConsoleApplication2
{
using System.Diagnostics;
using Castle.MicroKernel.Registration;
using Castle.Windsor;
class Program
{
static void Main(string[] args)
{
var container = new WindsorContainer().Register(
Component.For<Foo>().LifeStyle.Transient,
Component.For<Bar>().LifeStyle.Transient,
Component.For<Baz>().LifeStyle.Registration);
var foo = container.Resolve<Foo>();
Debug.Assert(ReferenceEquals(foo.Baz, foo.Bar.Baz));
}
}
public class Foo
{
private readonly Bar bar;
private readonly Baz baz;
public Foo(Bar bar, Baz baz)
{
this.bar = bar;
this.baz = baz;
}
public Bar Bar
{
get { return bar; }
}
public Baz Baz
{
get { return baz; }
}
}
public class Bar
{
private readonly Baz baz;
public Bar(Baz baz)
{
this.baz = baz;
}
public Baz Baz
{
get { return baz; }
}
}
public class Baz
{
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment