I am writing a multi-tenancy Platform As A Service solution, and trying to employ DDD approach. I have some basic, Core functionality which is default behaviour and has its services exosed to an API (application) layer. So far it all was straightforward, until I've started to write per-tenant, custom functionality (separated projects on top of Core). How do I extend base services to add custom behaviour?
For example, Core service:
namespace Core.Services
{
public class UserService
{
private readonly IUserRepository userRepository;
public User Get(Guid id)
{
userRepository.GetById(id);
}
public void Update(Guid id, UserStatus newUserStatus)
{
userRepository.UpdateStatus(Guid id, newUserStatus);
}
}
}
Now, I have a ClientA, who wants to, say, periodically rename users based on their activity and some other stuff:
namespace ClientA.Services
{
public class UserService // : Core.UserService ?
{
public void RenameInactiveUsers()
{
// something like
userRepository.UpdateAll(
condition: (user) => { user.NotActiveRecently() },
action: (user) => { user.Name = user.Name + " (inactive)" }
)
}
public void BanSuspiciousUsers()
{
userRepository.UpdateAll(
condition: (user) => { user.SomeSuspiciousFlag },
action: (user) => { user.Status = UserStatus::Banned }
);
}
// etc
}
}
So, how do I extend base services while still expose Get, Update and other methods to reuse the code?
Should it be inheritance? That way I will have to make private repositories, data and methods accessible in ancestors. Furthermore, inheritance in discourage in DDD as far as I know.
Or should for each tenant I create new UserService, which takes Core.UserService and expose identical contract, which will lead to many code like ClientA.UserService.Get(id) { return udnerlyingUserService.Get(id); } ?
Maybe, some third option?
--
You received this message because you are subscribed to the Google Groups "DDD/CQRS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dddcqrs+unsubscribe@googlegroups.com.
Visit this group at https://groups.google.com/group/dddcqrs.
For more options, visit https://groups.google.com/d/optout.