0
votes

In Onion framework, outer layer can access all the inner layers. If I go by this, my outer layer (which is UI layer/Controller in MVC) can directly access application/business services and repositories as well. Now, my controller can create a domain model and persist it in datastore by using repository. And thus bypass the validation and other business rules written in business layer. I believe, I am missing something. Please help.

public SpeakerController(IConferenceRepository conferenceRepository,
                         IUserSession userSession, IClock clock)
    : base(userSession) {
    _conferenceRepository = conferenceRepository;
    _clock = clock;
    _userSession = userSession; }

from http://jeffreypalermo.com/blog/the-onion-architecture-part-2/

1

1 Answers

1
votes

I say "no," though Palermo himself has indicated otherwise in twitter conversations. I say that each layer is allowed to talk to the next inner layer and not bypass it. The exception I make to this rule is if the functionality in question is basically just CRUD for reference data. I see no reason to introduce the additional complexity for this kind of data.

Another alternative is to have your repository implementation enforce the validation of business rules. Since the implementation is on the outermost layer of the onion, this should be pretty easy to do.

I have found Alistair Cockburn's Hexagonal Architecture illuminating and simpler that Onion Architecture. Basically there's "inside my application" and "outside my application." Anytime you need to cross that boundary, you need an adapter to protect your application from the implementation details.