A
A
Anton Starostin2014-11-27 21:24:04
C++ / C#
Anton Starostin, 2014-11-27 21:24:04

How to properly use N-Layer architecture?

Hello dear community!
Previously, they always helped me out on a toaster, I hope that now it will be possible to solve the problem.
Intro:
I have a program that is written in N-Layer style using DTO to transport data between layers.
In more detail, that is, there is a DAL, BLL, UI layer and a separate DTO layer where the data containers lie.
The DAL layer contains EF and the repository classes. Classes implement CRUD operations and all sorts of additional ones (more on that later).
Each entity has its own repository class (UserRepository, OrderRepository etc...). At the level above (BLL), I have service classes. These classes are separated by purpose (ImportService, ExportService, MediaService). And at the last level is the UI, which doesn't really declare anything other than the ViewModel. The UI simply instantiates the services and pulls the right methods, passing in the required parameters. It is worth mentioning the DTO, which defines containers that go from layer to layer.
That. when I receive a User object in the entity repository class, using AutoMapper I cast it to a container type and return it to the calling method from the service.
The essence of the problem:
Problems begin when I need to work out the architecture in more detail.
Let's say I have a service that checks users according to certain criteria, and then puts down the appropriate type for them. How to implement it correctly? Should I also create a repository class as intended and implement all the methods for the service to work in it? Or is it necessary to add all methods to the UserRepository class? (But the same GOD object is obtained). Or do you need to create methods, a la "GetValidTypeId", then get an identifier with this method and initialize all containers with it, and then give the collection on Update to the repository class?
Or maybe you should write a bunch of methods, like these for example: "SetUserValid", "SetUserInvalid"?
Conclusion:
In general, a lot of such questions arise all the time. Day by day I am visited by the thought that I am doing everything wrong and my approach is fundamentally wrong. I came to use this architecture myself, because one company asked why I did not make a test task based on it. I dug up the basics on the Internet, but I can’t find more details. I need sensible literature or a person to whom I can occasionally ask a couple of questions, after constructively filling them out and spending at least a couple of hours on the Internet in search.
Thank you in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Evseev, 2014-11-28
@Lixoradka

In my opinion, you have turned out to be too strict adherence to the principles of N-Layered Architecture and Repositiry Pattern. Everything seems to be done correctly, but this approach, in my opinion, does not cover all possible cases. You have come across one of these. Strict adherence to CRUD in the repository does not leave room for higher-level operations, since either they must be solved by a higher level, but then this will affect performance and complicate the code somewhat.
I can recommend reading the following.
By architecture:
habrahabr.ru/post/233747 - Onion architecture. Part 1
blog.8thlight.com/uncle-bob/2012/08/13/the-clean-a... - The Clean Architecture
• alistair.cockburn.us/Hexagonal+architecture - Hexagonal architecture
• Onion Architecture
○ jeffreypalermo.com/blog/the-onion-architecture-part-1
○ jeffreypalermo.com/blog/the-onion-architecture-part-2
○ jeffreypalermo.com/blog/the-onion-architecture-part- 3
○ jeffreypalermo.com/blog/onion-architecture-part-4-...
• blog.8thlight.com/uncle-bob/2011/09/30/Screaming-A...
About CQRS:
blog.byndyu.ru /2014/07/command-and-query-responsib...
blog.byndyu.ru/2014/05/blog-post.html
About Repository:
blog.byndyu.ru/2011/01/domain-driven-design-reposi ...
blog.byndyu.ru/2011/08/repository.html
lostechies.com/jimmybogard/2012/10/08/favor-query-...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question