【问题标题】:cannot build Caliburn Micro tutorial code. No definition for 'AssemblySource.Select'无法构建 Caliburn Micro 教程代码。 'AssemblySource.Select' 没有定义
【发布时间】:2014-07-01 23:04:45
【问题描述】:

我正在尝试按照http://www.mindscapehq.com/blog/index.php/2012/2/1/caliburn-micro-part-4-the-event-aggregator/ 的教程开始使用 Caliburn Micro

但是,教程中的代码会产生错误。在该页面上,提供了以下引导程序代码:

using Caliburn.Micro;
using System.ComponentModel.Composition;
using System.ComponentModel.Composition.Hosting;
using System.ComponentModel.Composition.Primitives;

public class AppBootstrapper : Bootstrapper<AppViewModel>
{
  private CompositionContainer container;

  protected override void Configure()
  {
    container = new CompositionContainer(new AggregateCatalog(AssemblySource.Instance.Select(x => new AssemblyCatalog(x)).OfType<ComposablePartCatalog>()));

    CompositionBatch 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));
  }
}

我找不到名为Bootstrapper 的类(通用或其他),但我已经能够扩展BootstrapperBase

但是,我在声明 container 的那一行遇到了麻烦。 AssemblySource 没有名为 Select 的方法。

那是什么?这是 2.0 版和 1.0 版之间的区别吗?如果是这样,我可以遵循一些更新的学习材料吗?

【问题讨论】:

    标签: c# wpf caliburn.micro


    【解决方案1】:

    1.5.2 和 2.0.0 之间发生了一些重大变化。其中大部分在documentation 中进行了概述。尽管似乎缺少对 Bootstrapper 的更改。这应该很快就会解决。

    你应该继承Bootstrapper,而不是继承Bootstrapper&lt;T&gt;,并添加一个类似

    的方法
    protected override void OnStartup(object sender, StartupEventArgs e)
    {
        DisplayRootViewFor<AppViewModel>();
    }
    

    到您的引导程序。

    缺少方法 Select 是因为 AssemblySource.InstanceIObservableCollectionSelect 方法是 LINQ 扩展方法。添加 System.Linq 的 using 将纠正该错误。

    【讨论】:

    • 我相信你的意思是继承自 BootstrapperBase 而不是 Bootstrapper。
    • 另外,我无法让我的应用程序运行我添加:public AppBootstrapper() { Initialize(); }
    猜你喜欢
    • 2013-05-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-29
    • 1970-01-01
    • 1970-01-01
    • 2012-10-12
    相关资源
    最近更新 更多