Closed vchelaru closed 6 months ago
I also replicated this issue on: Motorolla One 5G Ace - Android 10
You're building the service container twice so the event is responding to the proper instance.
I'm sorry can you clarify? The line that you linked only builds the service provider if it has not yet been built.
serviceProvider = serviceProvider ?? serviceCollection.BuildServiceProvider();
It is equivalent to:
if(serviceProvider == null)
{
serviceProvider = serviceCollection.BuildServiceProvider();
}
As far as I can tell, this prevents BuildServiceProvider from being built multiple times. Or are you saying that my call to BuildServiceProvider is redundant, and that something else is calling BuildServiceProvider outside of my code?
https://github.com/vchelaru/BleBug/blob/117416ce9cb8d5ec22344757fa8b24ba84c92975/BluetoothMauiTest1/MauiProgram.cs#L40 - builds container once and sets instance against MAUI events from .UseShiny()
You store the service collection, not the service provider, so once the static is hit, it builds the container again which is a different instance of the blemanager.
You should never be calling BuildServiceProvider yourself.
Thank you for the clarification. For future readers who may not be familiar, I was ablet to access the IServiceProvider by modifying my App's constructor so that it takes an IServiceProvider as a parameter:
public App(IServiceProvider serviceProvider)
{
// Use serviceProvider here if you want to do your own dependency injection and need to access IBleManager
...
Thank you for the clarification. For future readers who may not be familiar, I was ablet to access the IServiceProvider by modifying my App's constructor so that it takes an IServiceProvider as a parameter
I appreciate that you're trying to help others, but unfortunately - this is not a great practice dependency injection. Register your viewmodels as transients in your service provider and inject something like IBleManager into them
Component/Nuget
BluetoothLE Client (Shiny.BluetoothLE)
What operating system(s) are effected?
Version(s) of Operation Systems
Android 13.0
Hosting Model
Steps To Reproduce
Note - this requires that the app is run for the first time. If running subsequent times, the app should be uninstalled so that permissions are reset.
[CompatibilityChangeReporter] Compat change id reported: 78294732; UID 10303; state: ENABLED
[CompatibilityChangeReporter] Compat change id reported: 78294732; UID 10303; state: ENABLED