Caliburn.Micro and SimpleContainer

Caliburn.Micro and SimpleContainer

If you don’t want to use a fully fledged IoC container, then you can use the simple one Caliburn.Micro contains. It’s needed to support the Windows Phone development, but works with WPF, which is my interest.  It’s a source release, and you can get from Nuget, as Caliburn.Micro.Container.

Of course, Caliburn.Micro has it’s own direct access to any IoC, like this in a ViewModel ctor:-

public ShellViewModel()
{
windowsmgr = Caliburn.Micro.IoC.Get<IWindowManager>();
}

But it makes testing difficult and this direct use should be avoided.

What SimpleContainer allows you to do is this:-

public ShellViewModel(IEventAggregator events, IWindowManager wm)
{ 
this.events = events;
this.windowsmgr = wm;
}

Where SimpleContainer will inject the EventAggregator and WindowManager automatically, if set up in the Bootstrapper.

I’m attaching two examples, which work with CM 1.4.1, and for VS2012 and Net4.5.
One I wrote myself, and the other was added as a sample within Caliburn.Micro’s discussions, which I’ve updated.

It’s easier for you to read the code in the examples than for me to write any more here.

Have fun!

CM-SimpleContainerDemo.zip (2.81 mb)

CM-SimpleContainer-Sample.zip (2.81 mb)

Comments are closed.