The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

expp (2) [Avatar] Offline
#1
3.3.2 page 89 Options for accessing a repository.
You offer to pass repository to domain objects from services through parameters. it is efficient and simple way. But if i subclass my domain object and add some another logic to child class, how I provide addition repository which required for implements these additional functionality? I can't do that from the inherited operation's parameters list. I think that in this case RepositoryFactory or Repository's Singleton with hided implementations is more useful because all repositories are accessible from all entities through static class dependencies. Of course, This solution requires more difficult configurations for testing.
Is there way to extend my entities which use "repository through parameters" easy?

Oh, I forget the most important thing - thank you for you book. it turn my opinion on domain driven and pojos.
ceracm (110) [Avatar] Offline
#2
Re: how to access repository from domain object? again
Sorry for not replying sooner - December was a hectic month: holidays and JavaPolis.

You raise a very interesting issue.

One solution is rather than passing individual repositories as arguments pass a single ServiceLocator parameter. e.g.:

interface ServiceLocator {
Object getRepository(Class repositoryType);
}

(If you are using Java 5 - you could use generics)

This solves the subclassing problem as well as minimizing code changes when a method needs an additional repository.

I'd prefer this to using statics.

I hope this helps.

Chris