1 / 16

Implementing the Repository Pattern

Implementing the Repository Pattern. Mike Hadlow Mikehadlow@yahoo.com http://mikehadlow.blogspot.com. Data Access Taxonomy. Record Set / Data Set Record Set / Data Set + Business Object Active Record Business Object + Data Access Object Domain Model + ??. Repository. Aggregate.

zeal
Download Presentation

Implementing the Repository Pattern

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Implementing the Repository Pattern Mike Hadlow Mikehadlow@yahoo.com http://mikehadlow.blogspot.com

  2. Data Access Taxonomy • Record Set / Data Set • Record Set / Data Set + Business Object • Active Record • Business Object + Data Access Object • Domain Model + ??

  3. Repository

  4. Aggregate

  5. Repository • Encapsulate data access • Simple collection like interface • Should only return aggregate roots • Provide for adding and removing entities • Provide methods to select objects based on some criteria • Allow easy substitution

  6. QueryMethods Customer[] WithSurname(string surname)

  7. Specification Customer[] Find(ICustomerSpecification spec) boolICustomerSpecification.IsSatisfiedBy(Customer c) • Part of the Domain Model • Composable • Can define in-memory predicates and query predicates (SQL?) • Should we surface tool specific queries?

  8. Generic Repository IRepository<T> T[] Find<T>(ISpecification<T> specification)

  9. Rhino Commons

  10. Sharp Architecture

  11. Fluent NHibernate

  12. Is it a repository? • Does it show intent? • ICanDelete? ICanInsert? ICanUpdate? • Is polymorphism useful here? • But it’s ‘out there’!

  13. IQueryable? IQueryable<T> GetAll<T>() var customers = repository.GetAll().ThatMatch(criteria) .AsPagedList(pageNumber, pageSize); • SQL execution outside repository boundary • Query logic can seep into non-domain parts of the application

  14. Should Repositories control transactions? • Transactions should not be controlled by the repository. • Unit of Work (Nhibernate session, L2S DataContext) should not be controlled by the repository.

  15. Who consumes Repositories? • Views? • Controllers? • Domain Services? • Domain Entities?

  16. Questions? Mike Hadlow mikehadlow@yahoo.com http://mikehadlow.blogspot.com

More Related