Can Domain Service Access Repositories?

2,610 views
Skip to first unread message

Muhammad Bilal

unread,
Jan 6, 2015, 2:40:42 AM1/6/15
to ddd...@googlegroups.com
Hello Everyone!

I'm new to DDD. I have a scenario that I have some validations and some business rules which I need to perform, so I'm making some validation service(which is a domain service) and the service needs to access data from repository. So my question is that can we inject Repositories in Domain Service? Or should I pass the specific entities/VO to domain service which are needed for validation from Application Service? Please suggest me which approach is better?


Thanks,
Bilal

@yreynhout

unread,
Jan 6, 2015, 4:26:23 AM1/6/15
to ddd...@googlegroups.com
Yes, a domain service can access repositories.

Vincent van Dijk

unread,
Jan 6, 2015, 4:29:02 AM1/6/15
to ddd...@googlegroups.com
Using CQRS? Don't think it's a good idea to use aggregates for query purposes. Right?

Vincent.

--
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+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Muhammad Bilal

unread,
Jan 6, 2015, 5:23:18 AM1/6/15
to ddd...@googlegroups.com
Thanks for the reply,

But I'm not using CQRS right now.

Muhammad Bilal

unread,
Jan 6, 2015, 5:23:57 AM1/6/15
to ddd...@googlegroups.com
Alright Thanks :)

Greg Young

unread,
Jan 6, 2015, 7:21:39 AM1/6/15
to ddd...@googlegroups.com
If possible I would prefer to pass in the domain objects but there are some scenarios that doesn't make sense.
--
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+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Studying for the Turing test

Muhammad Bilal

unread,
Jan 6, 2015, 8:00:06 AM1/6/15
to ddd...@googlegroups.com
Yeah it seems more logical.

Thanks for the reply :)


On Tuesday, January 6, 2015 5:21:39 PM UTC+5, Greg Young wrote:
If possible I would prefer to pass in the domain objects but there are some scenarios that doesn't make sense.

On Tuesday, January 6, 2015, Muhammad Bilal <bilal...@gmail.com> wrote:
Hello Everyone!

I'm new to DDD. I have a scenario that I have some validations and some business rules which I need to perform, so I'm making some validation service(which is a domain service) and the service needs to access data from repository. So my question is that can we inject Repositories in Domain Service? Or should I pass the specific entities/VO to domain service which are needed for validation from Application Service? Please suggest me which approach is better?


Thanks,
Bilal

--
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.

For more options, visit https://groups.google.com/d/optout.

Greg Young

unread,
Jan 6, 2015, 8:27:32 AM1/6/15
to ddd...@googlegroups.com
Easier to test as well.


On Tuesday, January 6, 2015, Muhammad Bilal <bilal...@gmail.com> wrote:
Yeah it seems more logical.

Thanks for the reply :)

On Tuesday, January 6, 2015 5:21:39 PM UTC+5, Greg Young wrote:
If possible I would prefer to pass in the domain objects but there are some scenarios that doesn't make sense.

On Tuesday, January 6, 2015, Muhammad Bilal <bilal...@gmail.com> wrote:
Hello Everyone!

I'm new to DDD. I have a scenario that I have some validations and some business rules which I need to perform, so I'm making some validation service(which is a domain service) and the service needs to access data from repository. So my question is that can we inject Repositories in Domain Service? Or should I pass the specific entities/VO to domain service which are needed for validation from Application Service? Please suggest me which approach is better?


Thanks,
Bilal

--
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.
For more options, visit https://groups.google.com/d/optout.


--
Studying for the Turing test

--
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+u...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Muhammad Bilal

unread,
Jan 6, 2015, 11:55:13 PM1/6/15
to ddd...@googlegroups.com
Yes, exactly.

Thanks

Rasheed Amir

unread,
Jan 7, 2015, 3:09:35 AM1/7/15
to ddd...@googlegroups.com
Hi Greg,

Can you please list those scenarios in which it won't make sense?

I will always prefer to pass in the domain objects instead of injecting repository into the domain service.

Thanks,
/Rasheed


On Tuesday, January 6, 2015 1:21:39 PM UTC+1, Greg Young wrote:
If possible I would prefer to pass in the domain objects but there are some scenarios that doesn't make sense.

On Tuesday, January 6, 2015, Muhammad Bilal <bilal...@gmail.com> wrote:
Hello Everyone!

I'm new to DDD. I have a scenario that I have some validations and some business rules which I need to perform, so I'm making some validation service(which is a domain service) and the service needs to access data from repository. So my question is that can we inject Repositories in Domain Service? Or should I pass the specific entities/VO to domain service which are needed for validation from Application Service? Please suggest me which approach is better?


Thanks,
Bilal

--
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.

For more options, visit https://groups.google.com/d/optout.

Greg Young

unread,
Jan 7, 2015, 8:34:42 AM1/7/15
to ddd...@googlegroups.com
I need many of them or I need summary information that I query from the repository eg how many blue tickets are currently open (I don't want the 900 blue tickets, just the count)
To unsubscribe from this group and stop receiving emails from it, send an email to dddcqrs+u...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Rasheed Amir

unread,
Jan 7, 2015, 10:12:53 AM1/7/15
to ddd...@googlegroups.com
Got it thanks!

Greg Young

unread,
Jan 7, 2015, 10:19:58 AM1/7/15
to ddd...@googlegroups.com
Search the list for any case where you put a helper method on a repo and they are the scenarios I am referring to.
To unsubscribe from this group and stop receiving emails from it, send an email to dddcqrs+u...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Gabriel Palacios Moulergues

unread,
Jun 1, 2019, 10:25:32 AM6/1/19
to DDD/CQRS
I advocate using Repositories only in the Application layer.

Wouldn't the helper method on a repo be a sign that a new aggregate is needed and that a modeling opportunity has been missed?
If the currently open blue tickets count is needed to enforce a business rule, maybe you should load that into an aggregate to enforce that given rule?
If on the contrary, it is just needed for your Query side, you could build some read-only DAOs.
Reply all
Reply to author
Forward
0 new messages