maui
maui copied to clipboard
Add Support for KeyedServices
Description
ServiceProvider in Maui does not support KeyedServices
Steps to Reproduce
Microsoft.Maui.Controls.Application.Current?.Handler.MauiContext?.Services.GetRequiredKeyedService<T>(key);
Link to public reproduction project repository
No response
Version with bug
8.0.3
Is this a regression from previous behavior?
No, this is something new
Last version that worked well
Unknown/Other
Affected platforms
I was not able test on other platforms
Affected platform versions
No response
Did you find any workaround?
No
Relevant log output
System.InvalidOperationException: 'This service provider doesn't support keyed services.'
We've added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process.
Changing this to be a feature request rather than a bug, thanks!
Related PR: https://github.com/dotnet/runtime/pull/89509
Just a question, not a promise, do you think that this feature is not complex enough to the level that I can help with implementing it? I would like to help but I am not sure If I really can. Please let me know if I can help even partially. Thank you
@HakamFostok good question, I'm not sure. It could be as simple as roughly copying the changes and tests from https://github.com/dotnet/runtime/pull/89509 and applying to MAUI. Or does MAUI even get some of those changes for free due to possibly using the same types?
I'm paging @halter73 and @BrennanConroy who might have some insights about it. But at a glance it doesn't seem too complicated, so @HakamFostok if you want to spend a bit of time on it to see if maybe it's very easy, that could be worthwhile.
I know this is very far from complete, but I am not sure if I am on the right path or not, so I really need some guidance,
Please take a look at this commit, whenever you have the time https://github.com/dotnet/maui/commit/7d3ef3f6f43e6cceac9c1f30069a752a6640cce6
I am just trying to get feedback as soon as possible, and just start to put my foot on the path, this is not a full implementation by any means.
Thank you @Eilon @jfversluis
@HakamFostok thanks I also just saw that @mattleibow submitted https://github.com/dotnet/maui/pull/20014.
I am thinking we don't need to do much as we do use the same service provider from dotnet/runtime. Our issue is that we have a wrapper service because we need another feature. Our wrapper is missing the new interface.
Thank you a lot @Eilon. For me, the most important thing is to see this supported, no matter who does it. I really believe it is much better to be done by Microsoft itself, so I am very happy to see this happening ❤️ I am also glad that what I did was almost the same as the PR you mentioned (I did not write UnitTest at the time because I was not sure if I was on the correct path), but now I am very happy to see that the things I did were not completely crazy, that really makes me more confident in myself.
Thank you again all for your great efforts to make .NET and MAUI great products ❤️ I will delete my fork and hopefully, we will see this in .NET 9
@mattleibow can I use this with .NET 8 now, without waiting for .NET 9?
Yes. In 8.0.7 / SR2, we no longer block/crash the usage of keyed services.