Nullable Microsoft.Toolkit.Mvvm Ioc.Default.GetService vs. GalaSoft.MvvmLight SimpleIoc.Default.GetInstance #3846
-
|
What's best practice for addressing Looked at latest guidance on migration docs: https://github.com/windows-toolkit/MVVM-Samples/blob/01465e5d114441e0f50279853361670a4767e80b/docs/mvvm/MigratingFromMvvmLight.md cc: @Sergio0694, thoughts? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
|
Or maybe I should just be using |
Beta Was this translation helpful? Give feedback.
-
|
Hey @myokeeh, sorry for the delay, missed the notification! 😄 The Hope this helps! |
Beta Was this translation helpful? Give feedback.
Hey @myokeeh, sorry for the delay, missed the notification! 😄
The
GetServicemethod returnsnullbecause that's the official contract from theIServiceProviderinterface (see here). I would imagine that it's not that MvvmLight wasn't returningnullas well, it's more likely that it was just missing the nullable annotation, so you didn't see the return type as nullable, as you suggested. If you want to ensure the requested type is present and throw otherwise, then yeah I'd recommend usingGetRequiredServiceinstead, I added that extension specifically for this scenario 👍Hope this helps!