architecture,  Layers and Repository Pattern

Posted on 2011-05-03
Last Modified: 2013-12-16
Hi experts

I know it's a broad spectrum, but I hope you can help.

I'm implementing an small application for learning purposes, but I'm not sure if I'm understanding all the terms/definitions correct.

let's see, I have the following Projects

the MVC-Project (UI)
the Entitiy-Project with all entities
the Data-Project consisting of the Entity-Framework Model and the repository
the Business-Project which handles business logic

so, if you would seperate into different layer, it would look like this:

Data Access Layer
- Data Project

Domain Layer/Business Logic Layer
- Entitiy Project
- Business Project

- MVC Project

is this correct?

Is a Service Layer the same as a business layer?
when using the Repository Pattern, you do not create repository for every entity right?
Instead you create aggregates, which handle multiple entities
handles Persons and PersonAddresses

Does it make sense to have a entity project and a business-logic-project?
I actually could merge them, couldn't I?

if I leave it in two projects entitiy-project would consist of simple DTO's and
I would have to create a Business-Class for every entity, right?

So, I know those are many questions :-)
Hope you can help.

I'm working with VS2010 and .NET 4.0 (C#)
Question by:Arikael
    LVL 5

    Accepted Solution

    Huh!! Lots of questions:)

    Let me try to answer those questions.
    1). is this correct?
    A). Yes

    2). Is a Service Layer the same as a business layer?
    A). Nope.
    In a business layer(BL), there might be lots of business logic/features. But requirement wants to expose a few features from the BL to third parties (customers of the client).
    e.g. PlaceOrder, CancelOrder are features implemented in BL. But client wants to expose only PlaceOrder publicly. So customers of the client use "PlaceOrder" function in their application for placing an order. But an order can be cancelled by calling to client's Call center (which is opened 24x7).

    Consider Paypal API, lots of people are using Paypal api/features. It does not mean that whatever features ,are publicly accessible, provided by Paypal are the only features available in the Paypal application.

    3). when using the Repository Pattern, you do not create repository for every entity right?
    A). No.
    In some class/project, you might/will need to change only person's address.
    So, do not expose unnecessary features of the class through an object. If we combine the entities, then in somewhere we will be going to expose unnecessary features. [Encapsulation broken]

    4). Does it make sense to have a entity project and a business-logic-project?
    A). Yes
    If your team having more than one team member then BIG Yes.

    Database designer might create column "FName" in the "User" table. And other developer create property "FirstName" in the "User" class.

    5). I actually could merge them, couldn't I?
    A). Yes
    For team size one, BIG Yes.

    LVL 3

    Author Comment

    hehe thanks for your help :)

    it's very complex if you are new to all that stuff.

    One last (or two ;-) ) question about repositories and Domain Services.
    so, a repository should be responsible for aggregates (one or multiple entities).
    and a domain service comes into play when it doesn't make sense to put domain logic into an entitiy.

    let's say I have a Customer and Products (n-n, just to make it simple) and want to add Products to a Customer.

    Should I use a CustomerService or should handle this stuff in the Customer-Class (which would lead to a rather tight coupling between Products and Customers)?

    I assume I also would have a CustomerRepository, which leads to the following question.
    Aren't the Service and the repository rather similar. Because all the service would do is calling the repository which then adds the data (neglecting the fact, that the service probably does some validation or checks)


    LVL 5

    Assisted Solution

    by:Vipul Patel
    Repository, Domain, Entity, Layers, Service and more terms will be added in software development process later on.

    But fundamental should not be changed!

    Hope below links might be helpful to find your answer.

    Revert back me if you have any good links or references.
    LVL 3

    Author Comment

    thanks, very interesting.
    I read your links (and others, like the DomainDrivenDesignQuicklyOnline e-Book)

    just a question about repository and aggregates.
    An aggregate is basically just an entity which has some child entities?
    LVL 5

    Expert Comment

    by:Vipul Patel
    LVL 3

    Author Comment

    thanks for your help. I started implementing my application.
    If I have any further questions I will open a new question :)
    LVL 3

    Author Closing Comment

    great help, thanks

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Join & Write a Comment

    Introduction A frequently used term in Object-Oriented design is "SOLID" which is a mnemonic acronym that covers five principles of OO design.  These principles do not stand alone; there is interplay among them.  And they are not laws, merely princ…
    Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now