Repository Pattern - Doubt of use

2

Good night, guys.

I was developing software and started thinking about how best to implement Repository Pattern.

I have to return to the data controller of cities and states, so 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, for it I access the services and services, the repositories ... I started thinking then, would it be better to use an EnderecoService and within it add the state and city repositories? Or Create StateService and CityService? Or even use EnderecoService, but inside also have an EnderecoRepository that would return me States and Cities?

I would like to hear from you, how do you see the best approach and why.

Thank you!

    
asked by anonymous 09.09.2015 / 04:13

1 answer

1

It is possible and common to use one service per entity. However, an aggregate root service is also used. That is, for each set of relationships you choose a root, or main class, and create services for each of these sets.

I think this might be useful: DDD-Introduction .

In your case, then, I think I would create a EndereçoService that would handle everything related to this set, accessing the state and city repositories and others.

    
09.09.2015 / 15:22