Note that there are some explanatory texts on larger screens.

plurals
  1. POSeparation of Concerns the Repository Pattern & Entity Framework 3.5
    text
    copied!<p>I'm trying to be a better developer...</p> <p>What I'm working with:</p> <ol> <li>.Net MVC Framework 1.0</li> <li>Entity Framework 3.5</li> </ol> <p>I've been doing some reading and I think what i want to do is:</p> <ol> <li>Create a repository for each aggregate in the domain. An Order repository for example will manage an Order's OrderItems.</li> <li>Create a service layer to handle business logic. Each repository will have a corresponding service object with similar methods.</li> <li>Create DTOs to past between the repository and service</li> <li>Possibly create ViewModels which are classes for the View to consume.</li> </ol> <p>I have a base repository interface which my aggregate repository interfaces will implement...</p> <pre><code>public interface IRepository&lt;T&gt; { IEnumerable&lt;T&gt; ListAll(); T GetById(int id); bool Add(T entity); bool Remove(T entity); } </code></pre> <p>My Order Repository interface is defined as follows...there will likely be additional methods as I get more into this learning exercise.</p> <pre><code>public interface IOrderRepository : IRepository&lt;Order&gt; { } </code></pre> <p>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).</p> <ol> <li>The repository implementations will push and pull from the database using Entity Framework. When retrieving data; the methods will only return the DTOs and not the EF generated objects</li> <li>The services (as I'm calling them) will control the repository and perform the business logic. The services are what you will see in the controller i.e. _orderService.GetById(1).</li> <li>This is where I started flip flopping and could use some feedback...should I maybe have my service classes populate ViewModel classes...should I not have ViewModel classes....maybe that is too much mapping from one type to another?</li> </ol> <p>I would love to get some feedback on the direction I am heading with regards to a separation of concerns.</p> <p>Thanks</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload