Добавил реализацию репозитория для работы с БД

parent a8a13abd
using System.Collections.Generic;
using System.Linq;
using MyCities.Models;
namespace MyCities.Repositories
{
public class CityRepository : ICityRepository
{
private MyCitiesDbContext _dbContext;
public List<City> Cities => _dbContext.Cities.ToList();
public CityRepository(MyCitiesDbContext dbContext)
{
_dbContext = dbContext;
}
public void Add(City city)
{
_dbContext.Cities.Add(city);
_dbContext.SaveChanges();
}
}
}
......@@ -32,8 +32,8 @@ namespace MyCities
string connectionString = Configuration.GetConnectionString("Default");
services.AddDbContext<MyCitiesDbContext>(options => options.UseNpgsql(connectionString));
services.AddSingleton<ICityRepository, InMemoryCityRepository>();
services.AddSingleton<IPersonRepository, InMemoryPersonRepository>();
services.AddTransient<ICityRepository, CityRepository>();
services.AddTransient<IPersonRepository, InMemoryPersonRepository>();
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment