摘自 EventAggregator 上的 Caliburn Micro 文档:
// Creating the EventAggregator as a singleton.
public class Bootstrapper : BootstrapperBase {
private readonly SimpleContainer _container =
new SimpleContainer();
// ... Other Bootstrapper Config
protected override void Configure(){
_container.Singleton<IEventAggregator, EventAggregator>();
}
// ... Other Bootstrapper Config
}
// Acquiring the EventAggregator in a viewModel.
public class FooViewModel {
private readonly IEventAggregator _eventAggregator;
public FooViewModel(IEventAggregator eventAggregator) {
_eventAggregator = eventAggregator;
}
}
所以问题是如何让 Bootstrapper 创建的 EA 实例注入到你的 VM 中?
var svm = new SomeViewModel(?);
我尝试使用 Caliburn.Micro.IoC.Get 方法,但没有奏效......