Why such a complicated architecture?

Laurent Guigon 281 Reputation points
2022-11-29T15:27:13.473+00:00

Hi everybody

I'm following this tutorial on Blazor and I don't understand why to use such a complicated architecture. Why separate data access from the controller? Especially since the controller does nothing more than call the Repository... Why the Services ? What is the point of DTOs?

265305-solution.png265188-api.png265228-dtomodel.png265263-web.png

How do I make one that meets my needs? (nesting of collections: a subject with several chapters, a chapter with several sections, a section with several paragraphs, etc.)265217-mymcd.pdf
The use of the API, in my case, does not seem necessary to me, a project reference seems to me more appropriate.

I'd like to clean up my code and build SOLID/DRY/TDD app, but I don't have the understood of this, the reason to do like this (utility)

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,369 questions
0 comments No comments
{count} votes

Accepted answer
  1. AgaveJoe 27,581 Reputation points
    2022-11-29T16:19:13.037+00:00

    A layer architecture is standard practice which makes the code base easier to maintain. Since you are following a tutorial perhaps ask the author?

    Why separate data access from the controller?

    The data access library can be used by other clients. Plus the coding pattern is easier to test and update.

    Why the Services ?

    Testability. You can test the service without having to make an HTTP request to a controller. If there is a change to the business logic then only the service needs updating and the controller is not affected or vice versa.

    What is the point of DTOs?

    The user interface might consist of five tables. Rather than implementing five different HTTP requests a DTO can bundle the five datasets.

    How to implement Unit test code for this ? Test must be run on a test DB, not on the prod, right ?

    Depends on what you're testing. If you are testing the DB then the test is NOT a unit test but an integration test.

    0 comments No comments

4 additional answers

Sort by: Most helpful
  1. Bruce (SqlWork.com) 61,026 Reputation points
    2022-12-19T17:41:36.277+00:00

    unit tests should not access a database. this is one of the reasons to have a interface based data layer. you don't unit test the data layer, but rather do integration tests for it. all the higher layers will use a mocked or a test designed data layer.

    1 person found this answer helpful.
    0 comments No comments

  2. Laurent Guigon 281 Reputation points
    2022-11-29T15:49:31.173+00:00

    second question : How to implement Unit test code for this ? Test must be run on a test DB, not on the prod, right ?

    0 comments No comments

  3. Laurent Guigon 281 Reputation points
    2022-12-18T16:36:43.143+00:00

    Cool, The Author doesn't answer...

    0 comments No comments

  4. Laurent Guigon 281 Reputation points
    2022-12-26T10:26:43.47+00:00

    @Bruce (SqlWork.com)
    I'm not a TDD expert, have-you some doc to learn how to implemend good UT, please ?

    0 comments No comments