How is a Scoped service instance handled in a .NET Core Console application?

Viewed 13348

I copied this from ConfigureServices in a web application I'm building, where I'm trying to move away from the web and only use a console app or service:

serviceCollection.AddScoped<IDbConnection, SqlConnection>(c => new SqlConnection(App.Configuration.GetConnectionString("DefaultConnection")));

The console app works fine, but I'm wondering how the lifetime of the connection is handled. If and when is the connection closed and or disposed? Or does this behave the same as a transient instance, and I should dispose it myself?

1 Answers
Related