void DoSomething(bool callOtherService);
void DoSomethingElse(bool callOtherService);
class FooService : IFooService
protected Lazy<IBarService> _bar;
public FooService(Lazy<IBarService> bar)
public void DoSomething(bool callOtherService)
Console.WriteLine("Hello world. I am Foo.");
_bar.Value.DoSomethingElse(false);
class BarService : IBarService
protected Lazy<IFooService> _foo;
public BarService(Lazy<IFooService> foo)
public void DoSomethingElse(bool callOtherService)
Console.WriteLine("Hello world. I am Bar.");
_foo.Value.DoSomething(false);
protected readonly IFooService _foo;
protected readonly IBarService _bar;
public Application(IFooService foo, IBarService bar)
_bar.DoSomethingElse(true);
public static IContainer CompositionRoot()
var builder = new ContainerBuilder();
builder.RegisterType<FooService>().As<IFooService>().SingleInstance();
builder.RegisterType<BarService>().As<IBarService>().SingleInstance();
builder.RegisterType<Application>().SingleInstance();
public static void Main()
CompositionRoot().Resolve<Application>().Run();