Using Caliburn.Micro in an assembly called from an exe

Topics: Getting Started, UI Architecture
Jul 18, 2011 at 1:51 PM

I have created a little WPF application using Caliburn.Micro by following the documentation and using a MefBootstrapper.

I'd like to move this into an assembly so this functionality can be shared across a number of other applications.

I will be calling from some existing WinForms and from other WPF applications probably created using Caliburn.

I am struggling to figure out the basic layout of the components.

I have tried creating a basic Test application UI and using Caliburn.Micro with a RootViewModel. This has a method RunWizard wired to a button. 

I can't for the life of me figure out how to get my assembly called to run the moved code, i.e. what I should code in the RunWizard method.

Any pointers would be helpful but please don't waste your time if I am asking something unreasonable.

Cheers Dave.

Jul 18, 2011 at 1:59 PM

See if this thread helps:

Jul 18, 2011 at 3:52 PM

Thanks for the link - very helpful - turns out I had got pretty close myself.

Just need to figure out a little bit of dependency injection I'd like to allow client code to provide into the bootstrapper.

Top work to all involved.

Jul 19, 2011 at 10:15 AM

Have made a mod to my bootstrapper that sits in the class library.

The main change is to move the code from Configure to the constructor. The reason for this is the order in which these methods are called from the base boot strapper doesn't seem to allow me to easily inject the assemblies my views and view models will live in.

Maybe there is a better way of doing this. . . which is the point of me posting this.

    public class WizardBootstrapper : Bootstrapper

        private readonly CompositionContainer _container;

        /// <summary>
        /// The constructor has been customized compared to the original boot strapper from Caliburn.
        /// The reason for this base bootstrapper calls various methods to set itself up.
        /// By moving the wire up to the constructor and overriding the configue method we have slighty
        /// different control over the process. It allows us to inject in the probing assemblies.
        /// </summary>
        public WizardBootstrapper(IEnumerable<Assembly> probingAssemblies)
            : base(false)
            var listOfProbingAssemblies = probingAssemblies.ToList();
            // Iterate the assemblies and add to assembly source if not already there.
            // This is done becase we can instance the class multiple times
            foreach (var assembly in probingAssemblies)
                if (!AssemblySource.Instance.Contains(assembly))

            // Wire up the IOC we are using Composition (MEF).

            var assemblyCatalogs = AssemblySource.Instance
                .Select(x => new AssemblyCatalog(x));

            var aggregateCatalog = new AggregateCatalog(assemblyCatalogs);

            // pass above wire up components into MEF composition container.
            _container = new CompositionContainer(aggregateCatalog);

            // wire up the two Caliburn out of the box implementation of core interfaces.
            var batch = new CompositionBatch();
            batch.AddExportedValue<IWindowManager>(new WindowManager());
            batch.AddExportedValue<IEventAggregator>(new EventAggregator());



        protected override void Configure() {

            // Do nothing here. We need to do the configuration in the constructor.
            // The standard Configure method doesn't allow us to wire up the assembly sources.

        protected override object GetInstance(Type serviceType, string key) {
            var contract = string.IsNullOrEmpty(key) ?
                AttributedModelServices.GetContractName(serviceType) : key;
            var exports = _container.GetExportedValues<object>(contract);
            if (exports.Count() > 0) {
                return exports.First();
            throw new MissingContractException(contract);

        protected override IEnumerable<object> GetAllInstances(Type serviceType) {

            var contract = AttributedModelServices.GetContractName(serviceType);
            var exports = _container.GetExportedValues<object>(contract);
            if (exports.Count() > 0) {
                return exports;
            throw new MissingContractException(contract);

        protected override void BuildUp(object instance) {