can ServiceLocator.Current.GetInstance return null?
- by mauricio076
I have this piece of code (or similar) in many of our views:
private IEventAggregator eventAggregator;
Constructor()
{
eventAggregator = ServiceLocator.Current.GetInstance<IEventAggregator>();
...
}
I read from this post that ServiceLocator.Current can throw NullReferenceException (bad thing on a constructor) but I was wondering if the GetInstance<() method can return null (or some other inconsistent object) making eventAggregator dangerous to use later in other methods.
NOTE: I'm quite new to MVVM and WPF