locked
Repository Pattern explaination needed RRS feed

  • Question

  • Hi all,
    I hope you can clarify the following

    I would like to use the Repository Pattern (we are not using Linq to sql or entity framework) but (4000 stored procedure) legacy app.


    I have the following Assemblies
    MyCompany.Data.Repository
          CustomerRepository

    MyCompany.Business
          CustomerBiz


    now my question
    if I have the following Interface ICustomerRepository do I implement this interface to Both CustomerRepository and CustomerBiz or just to the Data Layer?

    Is the business layer not interface driven then?

    Thanks a lot


    Thanks for your help
    Wednesday, June 24, 2009 9:42 AM

Answers

  • Repository pattern's name describes itself. It's just a repository, intended for object storage.
    It solely depends on your project - the decision whether to use Repository directly from UI, or inject additional staff, like Facade, or Cache. But if your logic is rather trivial, using Repository directly from Presenter is enough.

    What do you mean by "Standardize Business Calls among all business object"?
    Why do you need to mock business objects? Usually it is necessary to mock DAL, or any other resource-related objects, but not objects related to the Domain.
    Vitaliy Liptchinsky http://dotnetframeworkplanet.blogspot.com/
    • Marked as answer by devBrix Friday, July 3, 2009 2:52 PM
    Wednesday, June 24, 2009 12:35 PM

All replies

  • If I understood your question correctly:

    MyCompany.Data.Repository.CustomerRepository class should implement ICustomerRepository interface, which should provide such methods, as:

    MyCompany.Business.CustomerBiz GetCustomerBiz(int someId){}
    void AddCustomer(CustomerBiz customer){}
    void Delete... etc...

    Vitaliy Liptchinsky http://dotnetframeworkplanet.blogspot.com/
    Wednesday, June 24, 2009 10:11 AM
  • you are absolutely correct and did a better job at explaining what I am doing. :)

    now
    Are you saying that the Business Layer does not implement and interface? EG

    public class CustomerBiz:ICustomerRepository   (is this wrong?)

    public class CustomerRepository:ICustomerRepository (this is correct) all clear to me.


    If the business layer does not implement an interface ,there is no contract between the business layer and the presentation layer or Presenter if you like.Is this correct?

    That is where my confusion comes in. I have a contract between Biz and DAL if you like via ICustomerRepository but nothing between Presenter and Business layer.

    Sorry if I sound confusing but that would help to clarify this.(I know it;s not all black and white ) by your view or anybody;s will help me

    Thanks again


    Thanks for your help
    Wednesday, June 24, 2009 10:24 AM
  • Repository pattern's purpose is to abstract domain layer from concrete DAL. Repository should reside in business layer. Your presenters should use Repository to operate over domain objects.
    Let's  have a look at dependencies here:
    UI layer -> Business layer -> DAL
    Here Repository patter should reside in Business layer. Therefore the only place in business layer which will keep reference to DAL is repository. And all presenters from UI layer will have reference to Repository.

    Does this answer your questions?

    Vitaliy Liptchinsky http://dotnetframeworkplanet.blogspot.com/
    Wednesday, June 24, 2009 11:57 AM
  • Yes and no.

    Repository pattern's purpose is to abstract domain layer from concrete DAL.
    Agreed and thanks for clarifying

    Repository to operate over domain objects.
    Not clear. I have both windows and Web Applications all sharing the same Business and Dal Layer and assemblies

    I have the following physical assemblies:
       MyCompany.UI.Windows.Application.exe  (Windows Forms) 
       MyCompany.UI.Web.Application.exe   (Web Forms)
       MyCompany.UI.Presenters.dll  (Shared by Win and Web)
       MyCompany.Business.dll
       MyCompany.Data.Repository.dll

    Flow
    MyCompany.UI.Windows.Application.exe or Web   >  MyCompany.UI.Presenters.dll >MyCompany.Business.dll > MyCompany.Data.Repository.dll

    Do I need a Business Interface to communicate between Presenter and Business.dll? EG IBusinessCustomer
    Some sort of BusinessPattern if you like or whatever name might be.


    This is where my confusion lays. May be I dont need that at all
    The reason is I go about this business Interface if makes sense is

    Standardize Business Calls among all business object
    Ability to mock the Business Object
    Consistency.

    any clearer?


    Thanks for your help
    Wednesday, June 24, 2009 12:11 PM
  • Repository pattern's name describes itself. It's just a repository, intended for object storage.
    It solely depends on your project - the decision whether to use Repository directly from UI, or inject additional staff, like Facade, or Cache. But if your logic is rather trivial, using Repository directly from Presenter is enough.

    What do you mean by "Standardize Business Calls among all business object"?
    Why do you need to mock business objects? Usually it is necessary to mock DAL, or any other resource-related objects, but not objects related to the Domain.
    Vitaliy Liptchinsky http://dotnetframeworkplanet.blogspot.com/
    • Marked as answer by devBrix Friday, July 3, 2009 2:52 PM
    Wednesday, June 24, 2009 12:35 PM