Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9124459
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:34:34+00:00 2026-06-17T06:34:34+00:00

I am comparing the possibilities for using services (in the sense of a process

  • 0

I am comparing the possibilities for using services (in the sense of a process local component like in the Windsor IoC container) from the domain model.

I have 3 ways to achieve this:

  1. Publishing a domain event and having service layer code handling it

  2. Injecting the service through a method on the model object

  3. Injecting the service in the model object

(4. Using a Service Locator)

The first leads to a very expressive and repetive pattern, creating domain events and handlers in a procedural style for otherwise simple tasks. But it has the best decoupling of the model from the environment it is used within (model is self defined).

The second makes methods arguments longer and looks like it breaks encapsulation (if the action of the model object requires other services, all callers have to change).

The third will inject Dependencies that are not required for the current Transaction. Also one needs to “extend” NHibernate for this. I would avoid this method due to other recommendations read.

As i want to write this in our documentation, i need to tell the reader when to use which method. I´m thinking something along the line “Use method injection if you would put the domain event handler into the model assembly”, but it does not really hit the point.

Suggestions for this rule?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T06:34:35+00:00Added an answer on June 17, 2026 at 6:34 am

    If an AR (aggregate Root) needs some data from a service, that data should be taken as a dependency (NOT the service). Basically, the AR won’t know about the service at all.

    If some method really has a depednency that wouldn’t make sense to be injected in the constructor, pass it as method argument. I don’t think you should pass the service though (but it depends), pass directly the data required.

    If the AR does something which will require a service to update stuff, I think the message driven is the way to go (generate an event).

    About NHibernate or other details, an AR doesn’t need to know about them. IF it isn’t a domain concept, keep it away from the AR.

    Personally, I try to model the AR so that it won’t need a service. It multiple AR are involved in a scenario, I’ll use domain events with a reliable service bus. This means any db transaction is out of the question. I keep the transactional stuff only within AR, more exactly in the AR repository, for everything else there is eventual consistency.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When comparing a tuple with a list like ... >>> [1,2,3] == (1,2,3) False
Possible duplicate : comparing-two-arrays I have two NSArray and I'd like to create a
When comparing to classic properties, what's the big gain of using it ? I
I am comparing two strings using following code string1.Contains(string2) but i am not getting
Simple problem, actually. I am trying to evaluate the possibilities of Google Apps, using
When comparing a string taken from console input to a string inside an array,
While comparing desktop and Mobile like Android, I want to know if the browser
When I am comparing two files in Eclipse (using, for example, Compare With -->
I'm comparing dates with something like this: var dt = new Date(); dt.setDate(17); dt.setMonth(06);
when comparing simple arrays, i use something like the following function to concatenate and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.