dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.11k stars 1.73k forks source link

Make SetCurrent / SetImplementation calls public #19057

Closed kanadaj closed 10 months ago

kanadaj commented 10 months ago

Description

It's been happening quite frequently that we've had to patch MAUI's implementation for a core service - previously we've had an issue with SecureStorage, and this time Connectivity throws on Android 14: https://github.com/dotnet/maui/issues/17861

It would be great if the static methods for setting the implementation were public so that consumers could replace those services when patching is needed.

This could also be done via DI I guess, and probably would be a better way to do it anyway, if at all possible.

Public API Changes

Primarily should involve public static helper classes: Preferences SecureStorage Connectivity Battery

And any other that uses the static singleton pattern (I don't know the full list from the top of my head) .

Intended Use-Case

This would be helpful when a bug appears in the framework which can often result in crashes until fixed. Service releases can take a while after an issue is found, and currently the only way to work around them is to use reflection to call the internal method, which isn't exactly ideal. I'm not even sure the methods to replace the implementation are retained on iOS without interpreter mode.

ghost commented 10 months ago

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.

jfversluis commented 10 months ago

Not sure if I understand, why can't you take the implementation, fix whatever you need and register that in your own DI container in your app? That's what the interfaces are for that we added for these APIs?

ghost commented 10 months ago

Hi @kanadaj. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

kanadaj commented 10 months ago

Not sure if I understand, why can't you take the implementation, fix whatever you need and register that in your own DI container in your app? That's what the interfaces are for that we added for these APIs?

Does that also override the static instances? Eg Preferences.Current. I don't remember seeing any documentation on that.

jfversluis commented 10 months ago

No that will not override the static instances, but I'm not sure if that is what you should want. If you want to provide your own implementation you can by creating an implementation based on the interfaces provided and use that.

I'm not really comfortable with exposing that many internal APIs while there is functionality available right now that let's you achieve what you want already.

I don't think we'll be changing this, so closing this one. Thanks for the suggestion!