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



DbContext has a scoped service lifetime because:

  1. It ensures that a new instance of DbContext is created per request
  2. DB connections are a limited and expensive resource
  3. DbContext is not thread-safe. Scope avoids to concurrency issues
  4. Makes it easier to manage transactions and ensure data consistency
  5. Reusing a DbContext instance can lead to increased memory usage