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

  • Home
  • SEARCH
  • 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 3315656
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:22:33+00:00 2026-05-17T22:22:33+00:00

This is a question about dependency injection. When constructing a service object, we pass

  • 0

This is a question about dependency injection. When constructing a service object, we pass in collaborators via the constructor in the construction phase. The service object would implement an interface, and that would be called during the run-phase.

Sometimes is is difficult to know if a particular object should be passed via the constructor or be part of the interface implemented by the service class?

Are there any rules about choosing one option over the other? The question is most difficult when you know the interface is only going to be called once in the scenario you are coding for.

  • 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-05-17T22:22:34+00:00Added an answer on May 17, 2026 at 10:22 pm

    I like to think of it like this:

    • Constructor arguments are implementation details
      • They are scoped to all operations
      • They do not change in response to any operation (invariant)
      • The interface can be understood without them
      • They are configuration values which reflect an application’s seams
    • Method arguments are contextual
      • They are scoped to an individual operation
      • They are runtime values which reflect an application’s data flow

    A lot of the art is in framing the problem correctly. For example, we might say to ourselves “I need to create a new row in the user table.” From that perspective, either of these signatures seems fine:

    void Insert(User user);
    
    void Insert(User user, IDbConnection dbConnection);
    

    However, we can break down our task definition:

    Intent: Create a new user

    Implementation detail: A user is a row in a table

    Let’s instead frame the task as “I need to create a user”. This gives us a way to evaluate the two signatures above, favoring the one which matches our intent:

    void Insert(User user);
    

    Analysis of an operation’s intent and the applicable scope of its data generally gives solid results.

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

Sidebar

Related Questions

I've this question about pass some instances by ref or not: here is my
I've been reading about dependency injection and have a simple question. I can understand
This question about Timers for windows services got me thinking: Say I have (and
Followed this question about delayed_job and monit Its working on my development machine. But
Note: I originally asked this question about an hour ago but only recently realized
I have seen this question about deploying to WebSphere using the WAS ant tasks.
Follow up to this question about GNU make : I've got a directory, flac
This is sort of the Java analogue of this question about C# . Suppose
JD Long helped me with this: question about manual annotation . But is it
A few days ago I asked this question about jquery ajax function invoking action

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.