E
E
Eugene2016-09-20 10:23:37
ASP.NET
Eugene, 2016-09-20 10:23:37

Three-tier ASP.NET MVC architecture. Where to validate data?

The bottom line is this, I need to implement a three-tier architecture in the project and ASP.NET MVC should act as the presentation layer. in the controller, we simply check the ModelState and, in case of an error, displays it in the view.
But in the case of a three-level architecture, as I understand it, validation should occur at the logic level (BLL), i.e. the controller must pass the data to the BLL level, then it is validated there, and in case of an error, the BLL must return some message to the controller so that it displays it in the view.
As an option, you can do a double check, i.e. at the UI level (in an MVC project) and in the BLL, then we will get rid of the problem of how to correctly display an error message to the user, but we will have to duplicate the checks because at the BLL level, the data must be validated.
Can someone explain how to implement this more correctly, and it is desirable to give any example.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Peter, 2016-09-20
@MiniBegemot

At the BLL level, you validate the occurrence of values ​​within the established boundaries and the correctness of the values,
and at the MVC level, the presence and correspondence of types.

M
MrDywar Pichugin, 2016-09-20
@Dywar

You can check at all levels.
1) MVC controllers - FluentValidation
2) Further, everything is through contracts .
Through IoC, we wrap everything in interfaces, and then:

[ContractClass(typeof(IArrayContract))]
public interface IArray
{ контракт }

[ContractClassFor(typeof(IArray))]
internal abstract class IArrayContract : IArray
{ проверка входных и выходных параметров контрактов }

+ checks on interfaces can be turned on and off on the project properties tab, 4 check levels.
+ checks are implemented in all types implementing the contract.
- you can’t just take and intercept the type of exception from the contract, you have to catch everything.
You cannot throw an HTTP error out of BBL, you will either have to make a filter, or catch them in each method and throw them through a switch, but this is not very good.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question