2
Good night, you guys.
I was developing a software and started thinking about what would be the best way to implement the Repository Pattern.
I have to return to the data controller of cities and states, for this I have two models in my application.
public class Estado
{
public int Id { get; set; }
public string Nome { get; set; }
public string Uf { get; set; }
public virtual ICollection<Cidade> Cidades { get; set; }
}
public class Cidade
{
public int Id { get; private set; }
public string Nome { get; set; }
public string Uf { get; set; }
public int IdEstado { get; set; }
public virtual Estado Estado { get; set; }
}
Then I use MVC , because I access the services and services, the repositories... I started thinking then, would it be better to use an Addressservice and add within it the States and Cities ? Or Create Statessrvice and Citiesrvice ? Or even use Addresservice, but inside also have an Addresscorepository that would return me States and Cities ?
I would like to know from you, how you see the best approach and why.
Thank you!
Do you use any OR/M for data access? If you are, I recommend that you do not use repostiory Pattern as an abstraction layer and use OR/M itself as abstraction. So you don’t lose important properties of your OR/m
– Eduardo Silva
I use the Entity, how this abstraction would work ?
– Kevin
I think Eduardo’s idea is to directly access the Entity from the controllers, with no repository or services to guide the repository. Many people who use MVC defend this architecture.
– RSinohara
Exactly, use the Entity directly in your services, so you can better use the EF resources without the limitation given by the repositories or daos
– Eduardo Silva
But this way I get some types of logic centralized in my controller, without being able to reuse in other platforms (a mobile for example). ).
– Kevin