C# – Onion Architecture Structure

Architecturecdesign-patternsdomain-driven-design

I am looking to understand and implement the Onion Architecture and have a vague idea on how to structure everything but need help to clear up some of my confusion.

Onion Architecture

Based on different examples and articles I Have read I created the above structure. One of my main confusion comes when I look at "02-Service: Services Interfaces". Lets take the IUserService.cs. I assume this interface would contain different signatures like RegisterUser(), LoginUser(), BanUser(), ModifyUser(), ChangeAuthenticationLevel() and so on? Is this correct? If not what other examples would we find? And are these considered Domain Services or Application Services?

Best Answer

I assume this interface would contain different signatures like RegisterUser(), LoginUser(), BanUser(), ModifyUser(), ChangeAuthenticationLevel() and so on? Is this correct?

No it is not. See, how there is User in each of those methods? That means it operates on user, and thus is part of the User entity. And as such, they should all be methods on User class and not part of service. Actually, from DDD perspective, Service is still part of the domain. It contains behavior that does not belong to any entity, but something like that should be extremely rare. For example, Repository is specific type of service.