public class VehicleRepository : IVehicleRepository { private List_vehicles; public VehicleRepository() { _vehicles = new List (); } public void AddVehicle(Vehicle vehicle) { _vehicles.Add(vehicle); } }
public class DbVehicleRepository : IVehicleRepository { private readonly DbContext _dbContext; public DbVehicleRepository(DbContext dbContext) { _dbContext = dbContext; } public void AddVehicle(Vehicle vehicle) { _dbContext.Vehicles.Add(vehicle); _dbContext.SaveChanges(); } }In this example, we create a new class called DbVehicleRepository that also implements the IVehicleRepository interface. This implementation stores the vehicles in a database using Entity Framework. We define a constructor that takes a DbContext as a parameter, which is used to interact with the database. The AddVehicle method adds the given vehicle to the Vehicles DbSet and saves changes to the database. Package/Library: The package/library that provides the IVehicleRepository interface is not specified in the examples given above. This interface could be provided by any number of packages/libraries that are designed to work with vehicles.