UserControls Library with Caliburn.Micro

Topics: Bootstrappers & IoC, UI Architecture
Apr 1, 2013 at 4:57 AM
Edited Apr 1, 2013 at 5:01 AM
I used the sample app tutorial to create a basic bootstrapper and it is working. I wanted to have all the UserControls in a separate library and just use those controls in the ShellView.

The sample WPF project can be seen over here:
The library I created is CaliburnControlLibrary and the controls UI is shoown as hello button in the shell view ..
But clicking on it does nothing ... what else needs to be done?
code: W54XLK
Apr 2, 2013 at 5:42 PM
I was able to resolve the issue by overiding SelectAssemblies like below.

protected override IEnumerable<Assembly> SelectAssemblies()
        List<Assembly> assemblies = new List<Assembly>();

        // Load new ViewModels here
        string[] fileEntries = Directory.GetFiles(Directory.GetCurrentDirectory());

        foreach (string fileName in fileEntries)
            if (fileName.Contains("MyCaliburnControlLibrary.dll"))

        return assemblies;
But in my ViewModel constructor I inject the DI container ..which is a NONO!
So how should i go about doing this?
    protected override void ConfigureContainer(ContainerBuilder builder)
              // good place to register application types or custom modules
        builder.Register<RibbonControlViewModel>(c => new RibbonControlViewModel(this.Container));
    public RibbonControlViewModel(IContainer container)
        this._container = container;

        this._windowManager = container.Resolve<IWindowManager>();
        this._eventAggregator = container.Resolve<IEventAggregator>();
Apr 3, 2013 at 3:10 AM

Modified the constructor to
public RibbonControlViewModel(IWindowManager windowManager, IEventAggregator eventAggregator)
        this._windowManager = windowManager;
        this._eventAggregator = eventAggregator;

And moved
        // register the single window manager for this container
        builder.Register<IWindowManager>(c => new CustomWindowManager()).InstancePerLifetimeScope();

        // register the single event aggregator for this container
        builder.Register<IEventAggregator>(c => new EventAggregator()).InstancePerLifetimeScope();
to before
// register view models
is called.

This ensure the objects are available for injection.