I'm trying to be a better developer...
What I'm working with:
I've been doing some reading and I think what i want to do is:
I have a base repository interface which my aggregate repository interfaces will implement...
public interface IRepository<T>
{
IEnumerable<T> ListAll();
T GetById(int id);
bool Add(T entity);
bool Remove(T entity);
}
My Order Repository interface is defined as follows...there will likely be additional methods as I get more into this learning exercise.
public interface IOrderRepository : IRepository<Order>
{
}
My service classes are essentially defined the same as the repositories except that each service implementation includes the business logic. The services will take a repository interface in the constructor (I'm not ready for IoC in this exercise but believe that is where I'd like to end up down the road).
I would love to get some feedback on the direction I am heading with regards to a separation of concerns.
Thanks
I think you are heading in the right direction about the Repository pattern. Regarding your question about the ViewModel classes, i suggest that you use something that transforms the output of the business service method outputs to some desired outputs. For example your Order business service may have a method called GetOrders()
. Using a custom attribute you may define the view class type for it. The view is able to get the output of this method, possibly joins it with other kinds of data and returns the result as a collection of objects with anonymous types. In this case the view will take IQueryable<Order>
or IEnumerable<Order>
as input and returns IList
as the output.
This method will help you greatly when you need to show different kinds of views of your data on the client side. We have already utilized something similar (but more complex) to this method in our company's framework.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With