views:

244

answers:

1

Hi!

I'm currently messing around with Rob Eisenberg's Caliburn framework. When looking at the documentation that is provided on http://caliburn.codeplex.com there is an example of how to resolve a Caliburn service from the container.

It's something along the lines of this:

SimpleContainer container = new SimpleContainer();

CaliburnFramework
            .ConfigureCore(container)
            .WithCommonDialogs()
            .WithPresentationFramework()
            .Start();

var service = container.GetInstance(typeof (IService)) as Service;

However what I am missing is a way to get a reference to the container anywhere in the app. Like this:

var service = Caliburn.Container.GetInstance(typeof(IService))as Service;

Do I have to build a custom static class that holds a reference to the container or is there something already built into Caliburn?

Thanks in advance and best regards!

+1  A: 

The latest trunk version of Caliburn automatically registers the container on framework startup as an service locator. You just have to reference Microsoft.Practices.ServiceLocation on your code and then ask the ServiceLocator for a instance of your service.

var service = ServiceLocator.Current.GetInstance<IService>();

Hope that helps.

Adriano Machado