Skip to content

Active loading and disposing of Dependency Injected Services #13

@TygreWolf

Description

@TygreWolf

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions