Three-tier C # application - where to put data and business models

I am creating a standard 3-tier application in C #

1 Console app for frontend / but I can change it to ASP.NET MVC webpage

2 Business logic layer

3 Data tier using Entity Framework connected to SQL database but this may change to windows azure

The main purpose is to display some customer data.

The client stored in the database has the following fields -

CustomerID
Firstname
Lastname
DateOfBirth
Othervalue1
Othervalue2
Othervalue3
Creationdate
Updatedate
IsDisabled //this represents "deleted" customers i.e. the app will never use deleted customers, but I want to keep them in the database anyway 

      

On average, I only want

CustomerID
Firstname
Lastname
DateOfBirth
Othervalue1
Othervalue2
Othervalue3
Updatedate

      

And in the interface for the first application, I will only show

CustomerID
Firstname
Lastname
DateOfBirth

      

How do I properly implement an n-tier application in terms of loading a Client from the datalayer (which may change) and using that Client in the middle tier and then in the presentation tier (which may change)?

Where can I place the Customer model? Do I need more than one? Do I need the ICustomer interface?

Project Details The project will be developed by two teams, one located in the US and the other in Eastern Europe, with four to five team members.

There is a legacy data access layer that this project will NOT use. Instead, we will create a new one with Entity Framework; we need to design and create a data layer that will be used in all new applications (for this application we only need a customer table and one or two tables). Other projects will add other tables to this layer.

I am using DI to inject an ICustomerRepository (see this SO question ). But will implement a repository and a unit of working templates.

I make sure to separate the layers appropriately. Over the next few months, we will add many new projects and the new data layer will grow rapidly. We're also looking at moving to Azure at some point, so I want to be able to replace the Entity Framework data layer without having to rewrite the business and front-end layers.

+3


source to share


1 answer


You have a data model (DB schema), a domain model and a view model.

If your goal is to separate the layers, you should have different classes representing the client in each of these three layers (but see @Joe's article mentions in the comments).

Your data access technology will map the data model to the domain model. If you are using Entity Framework, it provides a mapping capability between the two models.

For mapping a domain model to a view model, see Automapper for mapping between domain objects (such as business objects) and view models.

UPDATE

Based on your new information, I will tell you what I will do. This is, of course, not the only valid approach.



Given a distributed team, clear lines of responsibility are important. Different people, in different time zones, with different teams, will be working on the code.

Given that the new software is built on a legacy database, there are three things you should know:

  • It will not be easy to modify the legacy database to meet the needs of the new software.
  • New software should not be sub-optimal due to the structure of the existing database.
  • Data that will pollute the design of your current application may be needed in the next application you create.

I would do the following

  • Create data transfer objects (DTOs) that represent the structure of the legacy database.
  • Use the Repository and Job Templates to provide access to the DTO for the business object layer.
  • Create a business object layer (middle layer, whose classes are often called Entities) according to the needs of this application. Don't pollute your object design based on the DTO structure (ultimately the legacy DB structure).
  • Use technology such as Automapper to make it easier to set up your display between the two.
  • Create user interface objects (called models in MVC terminology) that represent the data that a given user interface screen processes (view in MVC terminology).
  • Depending on how closely the UI models match up with the Business Entities, you can use Automapper or just want to populate them in custom code.

Again, how do I approach it based on my experience, experience and preference. This is not the only valid approach.

+5


source







All Articles