One thing that i did wrong when played around with repository pattern - just like you, i thought that table relates to repository 1:1. When we apply some rules from Domain Driven Design - grouping repositories problem often disappears.
Repository should be per Aggregate root and not table. It means - if entity shouldn't live alone (i.e. - if you have a Registrant
that participates in particular Registration
) - it's just an entity, it doesn't need a repository, it should be updated/created/retrieved through repository of aggregate root it belongs.
Of course - in many cases, this technique of reducing count of repositories (actually - it's more a technique to structure your domain model) can't be applied because every entity is supposed to be an aggregate root (that highly depends on your domain, I can provide blind guesses only). In your example - License
seems to be an aggregate root because you need to be able to check them with no context of Registration
entity.
But that does not restrict us to cascade repositories (Registration
repository is allowed to reference License
repository if needed). That does not restrict us to reference License
repository (preferable - through IoC) directly from Registration
object.
Just try not to drive your design through complications provided by technologies or misunderstanding something. Grouping repositories in ServiceX
just because you don't want to construct 2 repositories ain't good idea.
Much better would be to give it a proper name - RegistrationService
i.e.
But services should be avoided in general - they often are cause that leads to anemic domain model.
EDIT:
Do start to use IoC. It truly eases the pain of injecting dependencies.
Instead of writing:
var registrationService = new RegistrationService(new RegistrationRepository(),
new LicenseRepository(), new GodOnlyKnowsWhatElseThatServiceNeeds());
you will be able to write:
var registrationService = IoC.Resolve<IRegistrationService>();
P.s. Would be better to use so called common service locator but that's just an example.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…