0

need convert project from caliburn.micro to normal caliburn. I have problem with bootstraper class.

I caliburn.micro look like this:

public class MefBootStrapper : BootStraper<IShellViewModel>
{
#region Fields
private CompositionContainer _container;
#endregion

#region Overrides
protected override void Configure()
{ //  configure container
#if SILVERLIGHT
    _container = CompositionHost.Initialize(
    new AggregateCatalog(AssemblySource.Instance.Select(x => new AssemblyCatalog(x)).OfType<ComposablePartCatalog>()));
#else

    var catalog =
        new AggregateCatalog(
            AssemblySource.Instance.Select(x => new AssemblyCatalog(x)).OfType<ComposablePartCatalog>());

    //add external DLL
    catalog.Catalogs.Add(
        new AssemblyCatalog(string.Format(
            CultureInfo.InvariantCulture, "{0}{1}", System.IO.Directory.GetCurrentDirectory(), @"\Pokec_Toolkit.dll")));

    _container = new CompositionContainer(catalog);
#endif

    var batch = new CompositionBatch();

    batch.AddExportedValue<IWindowManager>(new WindowManager());
    batch.AddExportedValue<IEventAggregator>(new EventAggregator());
    batch.AddExportedValue(_container);

    _container.Compose(batch);
}

protected override object GetInstance(Type serviceType, string key)
{
    string contract = string.IsNullOrEmpty(key) ? AttributedModelServices.GetContractName(serviceType) : key;
    var exports = _container.GetExportedValues<object>(contract);

    if (exports.Count() > 0)
    return exports.First();

    throw new Exception(string.Format("Could not locate any instances of contract {0}.", contract));
}

protected override IEnumerable<object> GetAllInstances(Type serviceType)
{
    return _container.GetExportedValues<object>(AttributedModelServices.GetContractName(serviceType));
}

protected override void BuildUp(object instance)
{
    _container.SatisfyImportsOnce(instance);
}

protected override IEnumerable<System.Reflection.Assembly> SelectAssemblies()
{
    return base.SelectAssemblies();
}
#endregion
}

I use MEF on injection.

Problem is in Caliburn doesn’t exist BooStraper class. How can I solve this?

I need load types from external assembly.

Thank for help

JMI
  • 11
  • 2

1 Answers1

0

Are you using latest source code? Bootstrapper was recently ported back to Caliburn.

Marco Amendola
  • 1,468
  • 11
  • 11