The questions that came up were:
- Do you use a Generic Repository that can work for any entity, or a Specialised one for each entity?
- Where are queries constructed?
- How do repositories move data in and out of the data store?
- What query language are you using (HQL, LINQ, SQL etc)?
- Where are transactions handled?
- Do entities know about the Repositories?
- What do your domain services do?
- What do your application services do?
- How do you test your repositories?
- Do ASPX pages talk to the domain too, or do they always go through application services?
In this post I'll summarise what I gleaned from Colin Jack.
####Colin Jack's Architecture
* Uses Specialised Repositories which have query methods such as
* Queries constructed inside the repository. Calling code doesn't have to know about persistence-specific query language. Also uses specification objects.
* Repositories use NHibernate to access the database using standard HQL or ICriteria. No DAOs are used from within the repository. Once fluent NHibernate matures, Colin may consider using the Repository they provide inside the specialised repositories to ease data access and help switch between in-memory and database-based testing.
* Transactions are handled way outside of the domain layer, in the Application Services. Often the session-per-request pattern is used and transactions committed at the end of the request.
* Entities aren't aware of repositories at all.
* Domain services live in the domain model, and take on responsibilities that might not fit well in an Entity.
* Application services communicate with the domain model (entities, repositories, domain services) to fulfill use cases. They may also handle things like sending emails and other app specific logic. If you have multiple GUIs, then you might share this logic in the application services.
* Repositories are tested against the database.
* Colin has tended to let apps talk directly to the domain where applicable.
See the discussion here on the Los Techies blog.
It was good to learn how others are using this stuff. Next I'll be writing up what I gleaned from Jimmy Bogard, who also made some great comments.
P.S - If anyone else wants to answer these questions, or add their own, feel free to do so in the comments below. You can use markdown in my comments for nicer formatting!