Look at how you can ensure that services are disposed of when using dependency injection with .NET Core Console applications.