Vikk
Vikk

Reputation: 3363

Where to put these kind of queries in DDD

I have an entity Institute and a repository InstituteRepository which fetches Institute objects based on criteria passed. Now somewhere in my application, I need ViewCount for the institute (No. of times the institute page has been viewed, which is stored and updated in a database table).

I cache my Institute objects, but since ViewCount is very dynamic, I would like to fetch it afresh everytime. Question is, where should I put my getViewCount() function?

Can I have a function like getViewCount() in InstituteRepository? If not, what's the best place for it?

Appreciate any help and sorry for the vague title.

Upvotes: 1

Views: 134

Answers (1)

Yves Reynhout
Yves Reynhout

Reputation: 2990

This would definitely fit in a separate bounded context that tracks "viewing related behavior". No need for a repository. Assuming you're using a relational datastore, just do an "insert into InstituteViewRecord (instituteid, user-who-viewed-id, date-and-time-of-viewing) values (...)" to track this information and a "select count(*) from InstituteViewRecord where instituteid = ". KISS. Any remoting needs can be satisfied using RPC or other mechanisms of messaging. I doubt this functionality is core domain.

Upvotes: 4

Related Questions