locked
Interaction between UnitOfWork and Repository patterns? RRS feed

  • Question

  • User-301840979 posted

    Another question about patterns.

    I read some article about unitOfwork and repository but i'm still confused about how they interact, and how to use them in the right way.

    I'm using an addressbook project to practise on patterns (even if , likely, patterns are not usefull) without any ORM framework for persistence.

    My domain objects are (at now) : AddressBook (acts as an application controller), Contact (contains information about each contact in the address book), ContactGroup (mantain collections of contact).

    Should i have to use distinct repository object for contact ad contactgroup?

    I thought to use a UnitOfWork for the operation about the adding/removing contact to group : the user can add existing contact to a group, create a new contact while adding it to the group or remove contact from group.

    Any help would be appreciated.

    Thanks.

    Monday, May 31, 2010 4:21 AM

Answers

  • User-1237044210 posted

    Hi liuc,    

    I really like practice project. Now you can show me your methodology in design your application. Domain Driven Design or not? 

    If you chose DDD, you can reference to my project at http://nma.codeplex.com/ for using UoW and Repository. I only noted you UoW is underline the Repository, if you apply UoW on your Repository, you must get UoW on each request (certainly UoW is a singleton).

    Or you can implement it as: separated your UoW with Repository. For examples, if you use Fluent NHibernate, UoW is get the Session into it and when the Repository want to commit a action, it must get the Session from UoW, and request the UoW commit for its the action.

    Come back to your scenario, you must define your root aggregate, and one root aggregate is created one Repository. If you thought all your application only have one root, it only have distinct repository. Or else maybe your application have more Repositories.

    If it have any point don't make sense for you, please tell me!

    Regards,

    ThangChung

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, June 1, 2010 1:36 PM