1

My question is in regards to the following:

If I have a class that manages users, lets call it UserManager. Should it be responsible for updating users in the database (something like RegisterUser, UpdateUser methods which uses a repository interface) in scenarios where a new user registers or updates profile?

I think this task can be delegated to another class. Something like UserSubscription class that handles calls(events) that are related to the UserRepository. I imagine this UserSubscription class of having methods (lets call them UpdateUser, SubscribeUser) that recieves ValueObject from UserManager class and uses them to update or register users. I think that this UserSubscription and UserManager classes could be in the same Aggregate in the Application Layer.

kayess
  • 3,384
  • 9
  • 28
  • 45
user2153675
  • 103
  • 7

1 Answers1

0

I think you might be looking for the repository pattern:

Mediates between the domain and data mapping layers using a collection-like interface for accessing domain objects.

A repository's responsibility should be loading / storing / updating users (in a database / other storage) in a generic way. See Repository Pattern Step by Step Explanation for more details.

If your UserManager does just this, it should be a UserRepository instead. However, if your UserManager's tasks are different, it should use the UserRepository for handling storage of users.

Matthias
  • 12,053
  • 4
  • 49
  • 91