can ServiceLocator.Current.GetInstance return null?
Posted
by
mauricio076
on Stack Overflow
See other posts from Stack Overflow
or by mauricio076
Published on 2012-07-05T22:51:34Z
Indexed on
2012/07/06
3:15 UTC
Read the original article
Hit count: 655
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
© Stack Overflow or respective owner