【问题标题】:Problem with converting project from Caliburn.Micro to "normal" Caliburn将项目从 Caliburn.Micro 转换为“正常”Caliburn 的问题
【发布时间】:2011-05-27 20:36:00
【问题描述】:

需要将项目从 caliburn.micro 转换为普通 caliburn。我对引导程序类有疑问。

我的 caliburn.micro 看起来像这样:

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
}

我在注射时使用 MEF。

问题在于 Caliburn 中不存在 BooStraper 类。我该如何解决这个问题?

我需要从外部程序集加载类型。

感谢帮助

【问题讨论】:

    标签: bootstrapper caliburn caliburn.micro


    【解决方案1】:

    您使用的是最新的源代码吗? Bootstrapper 最近被移植回 Caliburn。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-01-01
      • 1970-01-01
      • 2011-10-23
      • 2011-12-11
      • 1970-01-01
      • 2011-10-02
      • 1970-01-01
      相关资源
      最近更新 更多