Skip to content

Nullable Microsoft.Toolkit.Mvvm Ioc.Default.GetService vs. GalaSoft.MvvmLight SimpleIoc.Default.GetInstance #3846

Discussion options

You must be logged in to vote

Hey @myokeeh, sorry for the delay, missed the notification! 😄

The GetService method returns null because that's the official contract from the IServiceProvider interface (see here). I would imagine that it's not that MvvmLight wasn't returning null as 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 using GetRequiredService instead, I added that extension specifically for this scenario 👍

Hope this helps!

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by myokeeh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question ❔ Issues or PR require more information mvvm-toolkit 🧰 Issues/PRs for the Microsoft.Toolkit.Mvvm package
2 participants