从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;
}
}
Run Code Online (Sandbox Code Playgroud)
所以问题是如何让Bootstrapper创建的EA实例注入你的虚拟机?
var svm = new SomeViewModel(?);
我尝试使用Caliburn.Micro.IoC.Get方法,但这不起作用......