My Bootstrapper has the following code:
private SimpleContainer container; protected override void Configure() { container = new SimpleContainer(); container.Singleton<IEventAggregator, EventAggregator>(); container.PerRequest<InitialViewModel>(); } protected override object GetInstance(Type service, string key) { return container.GetInstance(service, key); } protected override IEnumerable<object> GetAllInstances(Type service) { return container.GetAllInstances(service); } protected override void BuildUp(object instance) { container.BuildUp(instance); }
In the OnStartup method, I call the DisplayRooViewFor
method:
protected override void OnStartup(object sender, StartupEventArgs e) { DisplayRootViewFor<InitialViewModel>(); }
This is the InitialViewModel:
private IEventAggregator eventAggregator; public InitialViewModel(IEventAggregator ea) { eventAggregator = ea; }
Unfortunately, it throws a NullReferenceException:
An exception of type 'System.NullReferenceException' occurred in Caliburn.Micro.Platform.dll, but was not processed in user code
I checked the CM source code and used the same code to verify it:
protected override void OnStartup(object sender, StartupEventArgs e) { var viewModel = IoC.GetInstance(typeof(InitialViewModel), null); var view = ViewLocator.LocateForModel(viewModel, null, null); ViewModelBinder.Bind(viewModel, view, null); var activator = viewModel as IActivate; if (activator != null) activator.Activate(); DisplayRootViewFor<InitialViewModel>(); }
Strange, there was no exception to these lines. Both views and the viewmodel have a link, and the InitialView constructor is called, but when it reaches and calls DisplayRootViewFor
, it throws an exception anyway.
What should i change?