Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Active loading and disposing of Dependency Injected Services #13

Open
TygreWolf opened this issue Jul 28, 2020 · 0 comments
Open

Active loading and disposing of Dependency Injected Services #13

TygreWolf opened this issue Jul 28, 2020 · 0 comments

Comments

@TygreWolf
Copy link

Hi Sean,

First, as a newbie to WPF, thank you so much for doing your series and tutorials. They have been quite invaluable over the past couple of months. Using your application as a template has been wonderful, but I had two questions surrounding the dependency injection process.

  1. The services registered with dependency injection are only constructed when the application needs them (i.e. switching to a view or viewmodel for the first time). Is there a preferred method for loading specific services ahead of time so that any required (and time-consuming) startup processes for those services might be loaded ahead of time?

  2. I have services that need to do cleanup, and so they inherit from IDisposable. I noticed those services that were loaded with dependency injection are not being disposed when the application closes. The ServiceProvider implementation itself also inherits from IDisposable, but is not being called (since the service provider only exists in the OnStartup method of the App (and not in some type of "using" statement). What is the preferred way to dispose of the service provider or any services registered within the service provider so that proper cleanup can occur?

Thanks for your help!

-Jason

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant