AvaloniaUI / avalonia-docs

https://docs.avaloniaui.net/docs/welcome
57 stars 187 forks source link

Enhance Dependency Injection guides #525

Open duongphuhiep opened 1 month ago

duongphuhiep commented 1 month ago

Hello,

The current example in the guide is not very helpful

https://docs.avaloniaui.net/docs/guides/implementation-guides/how-to-implement-dependency-injection

1) The ServiceProvider is created and available only inside the function OnFrameworkInitializationCompleted(), while it should be generally accessible to create object for us anywhere. Or How to make the avalonia framework use our ServiceProvider when creating object?

2) Is it really neccessary to Register the services (a.k.a the ServiceCollection) inside OnFrameworkInitializationCompleted()? We are registering the services, not actually create or use them, so why do we need to wait for OnFrameworkInitializationCompleted?

My suggesstion is