maui icon indicating copy to clipboard operation
maui copied to clipboard

Add Support for KeyedServices

Open HakamFostok opened this issue 1 year ago • 6 comments
trafficstars

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.'

HakamFostok avatar Nov 23 '23 18:11 HakamFostok

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.

ghost avatar Nov 27 '23 10:11 ghost

Changing this to be a feature request rather than a bug, thanks!

jfversluis avatar Nov 27 '23 10:11 jfversluis

Related PR: https://github.com/dotnet/runtime/pull/89509

Eilon avatar Nov 28 '23 20:11 Eilon

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 avatar Jan 09 '24 18:01 HakamFostok

@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.

Eilon avatar Jan 09 '24 19:01 Eilon

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 avatar Jan 11 '24 16:01 HakamFostok

@HakamFostok thanks I also just saw that @mattleibow submitted https://github.com/dotnet/maui/pull/20014.

Eilon avatar Jan 20 '24 00:01 Eilon

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.

mattleibow avatar Jan 20 '24 04:01 mattleibow

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

HakamFostok avatar Jan 20 '24 11:01 HakamFostok

@mattleibow can I use this with .NET 8 now, without waiting for .NET 9?

HakamFostok avatar Feb 14 '24 16:02 HakamFostok

Yes. In 8.0.7 / SR2, we no longer block/crash the usage of keyed services.

mattleibow avatar Feb 14 '24 20:02 mattleibow