Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Services and Authorization in Onion Architecture

I'm trying to learn Onion Architecture and as i understand, I've organized my solution as follows:

Domain

  • Domain.Entities (Business objects)
  • Domain.Interfaces (Interfaces for domain services and repositories)
  • Domain.Services (Implementation for domain services interfaces)

Infrastructure

  • Infrastructure.Data (Implementation for repositories and unit of work with EF)
  • Infrastructure.DependencyResolution (Implementation for IoC with Unity)

UI

  • UI.WebMVC

And here are my questions:

1- Am i right with these layers or i'm missing something ?

2- As for services that are related to a specific technology (e.g. Logging), where their interfaces should be (Domain.Interfaces or Infrastructure.Interfaces) ?

3- As i understand, The Domain Service will process my business use case so what are the benefits i'll get from application service

4- What are the differences between Domain Service and Application Service and in which project Application Service interfaces should be?

5- Should User Authorization process be a part of Application Services or Domain Services?

like image 504
Mahdy Avatar asked Sep 15 '14 08:09

Mahdy


1 Answers

enter image description here

  1. This a schema of hexagonal architecture, but it's really close to onion and IMO you should use that. Here are shown 3 layers: domain (yellow), application (red), infrastructure (green + blue). So answering your question - you are missing few pieces like application services.

  2. Logging is probably not part of your domain logic, so it should be in infrastructure, both interface and implementation. To use it, you have to inject it to your application layer.

  3. Domain services are taking care only of things that are related to your businness. Application services are most of the time preparing ground for domain services, in example creating repositories and retrieving aggregates from it, then calling domain services and passing that aggregates there. You shouldn't handle your business logic in app layer!

  4. As I wrote in point 3. Application services should be in every projects that are using domain services.

  5. Depends. User request your infrastructure layer with user credentials, infrastructure layer calls application layer with that credentials, there you try to retrieve user with given credentials, but first you convert raw password to hashed one with some functions. If user is found, you can authenticate user in infrastructure layer. Domain service wasn't needed here, but it's an exception.

like image 171
Rafał Łużyński Avatar answered Sep 22 '22 16:09

Rafał Łużyński