Caliburn.Micro and Ninject example

Apr 2, 2011 at 10:46 AM
Edited Apr 2, 2011 at 10:48 AM


I've just started to learn Caliburn.Micro and as I'm using Ninject instead of MEF I wonder if there are anyone out there who's got an example on how to set up a custom Caliburn bootstrapper with Ninject?


-- norgie

Apr 2, 2011 at 11:26 AM
Edited Apr 2, 2011 at 11:33 AM

Here's a stripped-down (and untested) version from a project I did, shows the very basics:

namespace NinjectSample
	using System;
	using System.Collections.Generic;
	using System.Reflection;
	using System.Windows.Controls;
	using System.Windows.Data;
	using Caliburn.Micro;
	using Ninject;

		Justification = "Entry class is never Disposed, cleanup handled already by OnExit")]
	public sealed class NinjectBootstrapper : Bootstrapper<IShell>
		#region Fields
		private IKernel _kernel;
		#region Base functionality overrides
		protected override void Configure()
			_kernel = new StandardKernel();



		protected override void OnExit(object sender, EventArgs e)
			base.OnExit(sender, e);
		#region IoC method overrides
		protected override object GetInstance(Type serviceType, string key)
			if (serviceType != null)
				return _kernel.Get(serviceType);

			throw new ArgumentNullException("serviceType");

		protected override IEnumerable<object> GetAllInstances(Type serviceType)
			return _kernel.GetAll(serviceType);

		protected override void BuildUp(object instance)

You'll probably want to check out this post as well.

Apr 2, 2011 at 3:15 PM

Thanks for the quick reply. I'll have a closer look at this later (as well as the other post as well).