5.1. Set Connection String
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning",
"Microsoft.EntityFrameworkCore.Database.Command": "Warning"
}
},
"AllowedHosts": "*",
"ConnectionStrings": {
"GameStore": "Data Source=GameStore.db"
}
}
5.2. Dependency Injection
- IServiceProvider: Service Provider.
DbContext has a scoped service lifetime because:
- It ensures that a new instance of DbContext is created per request
- DB connections are a limited and expensive resource
- DbContext is not thread-safe. Scope avoids to concurrency issues
- Makes it easier to manage transactions and ensure data consistency
- Reusing a DbContext instance can lead to increased memory usage