Jeremy
Jeremy
CC#
Created by Impulsive on 11/23/2024 in #help
.NET 8.0, PostgreSql and left over Idle sessions
A common approach would be to make repository interfaces for handling your CRUD operations on each table. Then make concrete classes that implement those interfaces, using your sql connections and commands. Other code should reference the interfaces, with the implementations injected using DI. Typically for a web app you'd want to use Scoped, so the service is the same for each request. Transient would create a new service every single time it's needed, even within one request. Usually the scope is the controller and you inject the repository to the controller constructor. If you have a bunch of business logic beyond simple CRUD, you can add another service layer between the controller and repositories. E.g. the CarController gets an ICarService, which coordinates all the appropriate calls to the ICarRepository, ILicensePlateRepository, IVehicleTitleRepository, etc.
19 replies