Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The answer is <strong>no</strong> if you do not need to be able to switch ORM or be able to test any class that has a dependency to your ORM/database.</p> <p>If you want to be able to switch ORM or be able to easily test your classes which uses the database layer: Yes you need a repository (with an interface specification).</p> <p>You can also switch to a memory repository (which I do in my unit tests), a XML file or whatever if you use repository pattern.</p> <p><strong>Update</strong></p> <p>The problem with most repository pattern implementations which you can find by Googling is that they don't work very well in production. They lack options to limit the result (paging) and ordering the result which is kind of amazing.</p> <p>Repository pattern comes to it's glory when it's combined with a UnitOfWork implementation and has support for the Specification pattern.</p> <p>If you find one having all of that, let me know :) (I do have my own, exception for a well working specification part)</p> <p><strong>Update 2</strong></p> <p>Repository is so much more than just accessing the database in a abstracted way such as can be done by ORM's. A normal Repository implementation should handle all aggregate entities (for instance <code>Order</code> and <code>OrderLine</code>). Bu handling them in the same repository class you can always make sure that those are built correctly.</p> <p>But hey you say: That's done automatically for me by the ORM. Well, yes and no. If you create a website, you most likely want to edit only one order line. Do you fetch the complete order, loop through it to find the order, and then add it to the view?</p> <p>By doing so you introduce logic to your controller that do not belong there. How do you do it when a webservice want's the same thing? Duplicate your code?</p> <p>By using a ORM it's quite easy to fetch any entity from anywhere <code>myOrm.Fetch&lt;User&gt;(user =&gt; user.Id == 1)</code> modify it and then save it. This can be quite handy, but also add code smells since you duplicate code and have no control over how the objects are created, if they got a valid state or correct associations.</p> <p>The next thing that comes to mind is that you might want to be able to subscribe on events like Created, Updated and Deleted in a centralized way. That's easy if you have a repository.</p> <p>For me an ORM provides a way to map classes to tables and nothing more. I still like to wrap them in repositories to have control over them and get a single point of modification.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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