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 9239795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:04:09+00:00 2026-06-18T08:04:09+00:00

Reading some interesting books on Domain driven design, one sample is as follows: //

  • 0

Reading some interesting books on Domain driven design, one sample is as follows:

// Order
IOrderNumberService orderNumberService;
public void Accept()
{
    this.orderNumber = this.orderNumberService.GetNextAvailableNumber();
}

What is not shown in the above code, is that the OrderNumberService has been injected by a IoC framework. We don’t know the lifetime scope of the service object (a new service could be created for every injection, or a singleton injected every time).

For a service whose job it is to check the next useable number from a database, I see no state required and could safely (probably should) use a Singleton.

For this case, I don’t see the need to swap out this service and could just as easily call the singleton class concrete implementation directly OrderNumberService.GetNextAvailableNumber(), or at least if I needed to abstract with an interface I could always refactor later at that time.

Aside from abstracting the service interface from the implementation allowing easier testing, are there any other benefits of injecting the service?

I am wary of putting all the things I have read in to code just because they are cool – so at what point does abstraction create so many layers it makes code harder to read and what are the warning signs one should be mindful of?

  • 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-18T08:04:12+00:00Added an answer on June 18, 2026 at 8:04 am

    Services don’t have state in DDD (Evans p. 107), no matter to which layer they do belong

    When a significant process or transformation in the domain is not a
    natural responsibility of an ENTITY or VALUE OBJECT, add an operation
    to the model as a standalone interface declared as a SERVICE. Define
    the interface in terms of language of the model and make sure the
    operation name is part of the UBIQUITOUS LANGUAGE. Make the service
    stateless

    Using high level abstractions(interfaces) instead of the implementations(classes) is Dependency Inversion principle, and is not a Dependency Injection, Dependency Inversion is about relations of abstractions and implementations, while Dependency Injection is about removing hard coded dependencies – even if your field is an interface you still need to initialize it somehow, i.e assign a value to some class instance.

    As for the technology for injecting the service instance, DDD is technology agnostic. If you think that using an IoC container makes things harder to read you may consider using Service Locator pattern instead, for the full reasoning see Martin J Fowler article on DI containers. But tbh DDD requires some sophisticated team(Evans mentioned it in some talks on infoq) so I think that it will be people who will be able to grasp IoC concepts, so Service Locator gives no big advantages here(except maybe if you are working is some limited environments like Android phones where the IoC framework is too heavyweight solution)

    As for the infamous singleton pattern (implemented with a static class method) I don’t think that it is suitable at all because it’s not testable.

    Also DDD promotes using lightweight frameworks (See Architectural Frameworks, Evans p. 74), and the contemporary frameworks (Spring, Fluent NHibernate, etc.) are developed with this in mind so they are actually designed to make working with POJO/POCO simpler (you can read more in a set of articles on framework design, written by the Fluent NHibernate architect Jeremy Miller http://codebetter.com/jeremymiller/2010/01/11/patterns-in-practice-a-retrospective/), many Spring projects, for example reference DDD directly. So it’s unlikely that the framework will force you to put a dependency in your code, or make it less readable – it will rather use reflection API to set the values, and will use some non-intrusive approach like XML or attributes(annotations) for the configuration.

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

Sidebar

Related Questions

I was reading some tutorial about openGL in qt. One of the mouse event
I was reading some c++ code, and i saw something interesting. The code was
After reading some interesting posts here on SO, and many pages found on google,
So I did some reading of the related questions and had some interesting stuff
I am reading some product pages in python/BS4 and find an interesting variety in
I'm fairly new to programming but I've been reading some interesting discussions on StackOverflow
Reading some questions here on SO about conversion operators and constructors got me thinking
Reading some posts from Jimmy Boggard and wondering - how exactly is it possible
Reading some Verilog code, there seem to be two ways of defining arguments in
When reading some FreeBSD source code (See: radix.h lines 158-173), I found variable declarations

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.