Application Layer

2

Based on this question and this other question , in an environment that uses Entity Framework and Asp.net MVC .

I see in many examples not using the application layer, a use of the data layer ( Entity Framework ) in Controller . Then come my first doubt:

Is it really necessary to use this layer? And what are the advantages of using it?

Following the rationale, in an environment where there are no data exclusions, rather an active field.

In order to list the data and delete it (change the value of the active field):

Which layer is responsible for this? The data access layer, the application layer, or Controller ?

The last question is regarding includes.

Implementing this method in the data layer ( Entity Framework ):

 public IQueryable<T> Query(params Expression<Func<T, object>>[] includes)
    {
        IQueryable<T> Set = this.Query();
        foreach (var include in includes)
        {
            Set = Set.Include(include);
        }
        return Set;
    }

It would be the duty of the application layer to tell which features it will use or the Controller ?

In the background, it is not very clear to me what the real responsibility of the application layer is.

Until then, my only responsibility was to make the user interaction layer ( Controller ) not have to be related to the data layer.

    
asked by anonymous 05.09.2014 / 21:29

1 answer

3

Is it really necessary to use this layer (repository)? And what are the advantages of using it?

Not required.

The advantage of the layer is to be able to write unit tests more easily, because instead of injecting classes into repositories that effectively access data, you can inject other things, such as other classes that work with dummy and controlled data.

Which layer is responsible for this (data persistence)? The data access layer, the application layer, or the Controller?

The data access layer only abstracts the database operations as you add, change, delete, or select objects. It is what turns an object into a data element that your database understands.

The application layer, in an MVC context, is almost superfluous, because the data interaction of different models is already done by the Controller .

Therefore, the objects change is Controller and the Models rules, and actually perform the operation is the data layer's responsibility.

Is it the duty of the application layer to tell which features it will use or the Controller?

No. In theory, the application layer organizes and validates data coming from the presentation. The Include causes you to force the Entity Framework to load a given data in advance (by taking advantage of the join feature of a relational database, for example, and improving performance).

As your application is being developed, Controller is becoming a hollow, non-functional layer. The correct thing would be to leave the application layer concept aside and just use Controller .

    
05.09.2014 / 21:51