I have seen many tutorials that implement with EF a repository pattern and UoW, but I do not see it necessary since DbSet and DbContext already are. So I decided to simplify it without the implementation but adding services such as that.
public class HomeController : Controller
{
private IdbContext _dbContextUoW;
private IClientService _clientService;
public HomeController (IDbContext dbContextUoW,IClientService clientService){//IoC
this._dbContextUoW = dbContextUoW;
this._clientService = clientService;
}
public ActionResult Index()
{
List<Client> clients;
clients = List<Client>this._clientService(this._dbContextUoW).GetAll();
//this._dbContextUoW.SaveChanges()
return View();
}
protected override void Dispose(bool disposing)
{
this._dbContextUoW.Dispose();
base.Dispose(disposing);
}
}
public interface IClientService
{
List<Client> GetAll();
}
public class ClientService: IClientService
{
private IdbContextUoW _dbContextUoW;
public ClientService(IDbContext dbContextUoW){
this._dbContextUoW = dbContextUoW;
}
public List<Client> GetAll(){
return ...
}
}
Is this implementation correct? am'I on the right track?
Aucun commentaire:
Enregistrer un commentaire