locked
IRepository Pattern RRS feed

  • Question

  • User-305496339 posted

    Hi Friends,

    I was wondering if I am using the IRepository Pattern should I structure my project files where these Repository Interfaces are in a folder. And if I do place them in a folder would i need to use a file path to access them? Also is the Repository pattern considered the Data Access Layer? Oh, and one more question. I have always been a little confused about what is considered the Business Logic Layer and what Classes or Methods would be a part of this layer. Thanks for any help. 

    Tuesday, June 25, 2019 2:09 PM

Answers

  • User-821857111 posted

    I tend to place interface classes in the same folder as their implementations, to save messing around with different namespaces.

    Repositories tend to sit in a layer between data access (the actual part of the app that communicates with the data store, typically being dependent on ADO.NET) and business logic. Kind of. Entity Framework merges repositories and data access in one layer. 

    Flow of communication is usually like this:

    Controller > Business Logic/Service > Repository/EF > Data Store (and back again). Often business logic classes contains methods that make calls to the repository layer without any additional code, but that is where you would add any logic that relates to the business rules of the application. 

    EDIT: "Controller" in this context could be an MVC controller or a Page Controller (e.g. Code Behind in Web forms or PageModel class in Razor Pages)

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, June 25, 2019 2:25 PM
  • User-821857111 posted

    It largely depends on the size and nature of the application and use of the method. If the method might be used by other applications, you could put it in a class library project and create a Nuget package out of it. Otherwise I might just put in a folder, which might house other random utility methods or be devoted to classes and methods related to pay calculations. There's no right or wrong answer. In fact, it's quite common to put this sort of thing in one place, and then move it somewhere else as the code base evolves.  

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, June 25, 2019 8:39 PM

All replies

  • User-821857111 posted

    I tend to place interface classes in the same folder as their implementations, to save messing around with different namespaces.

    Repositories tend to sit in a layer between data access (the actual part of the app that communicates with the data store, typically being dependent on ADO.NET) and business logic. Kind of. Entity Framework merges repositories and data access in one layer. 

    Flow of communication is usually like this:

    Controller > Business Logic/Service > Repository/EF > Data Store (and back again). Often business logic classes contains methods that make calls to the repository layer without any additional code, but that is where you would add any logic that relates to the business rules of the application. 

    EDIT: "Controller" in this context could be an MVC controller or a Page Controller (e.g. Code Behind in Web forms or PageModel class in Razor Pages)

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, June 25, 2019 2:25 PM
  • User-305496339 posted

    Thanks for your help. I was wondering what if you wanted a method that calculated pay differently based on the type of employee. Where would you put that Class method in the folder structure of your web application? Thanks !!!

    Tuesday, June 25, 2019 3:37 PM
  • User-821857111 posted

    It largely depends on the size and nature of the application and use of the method. If the method might be used by other applications, you could put it in a class library project and create a Nuget package out of it. Otherwise I might just put in a folder, which might house other random utility methods or be devoted to classes and methods related to pay calculations. There's no right or wrong answer. In fact, it's quite common to put this sort of thing in one place, and then move it somewhere else as the code base evolves.  

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, June 25, 2019 8:39 PM