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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:13:05+00:00 2026-05-28T05:13:05+00:00

Normally when I need to inject one or more services into another service, I

  • 0

Normally when I need to inject one or more services into another service, I explicitly inject each one. However, I have a situation where injecting the service container itself will really make things easier. I know this is not a recommended practice, but I’m curious what the technical reasons are for discouraging this. Is it something legitimate like it’s too resource intensive, or a more personal feeling that it’s too messy?

  • 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-28T05:13:06+00:00Added an answer on May 28, 2026 at 5:13 am

    If you inject the container, you’re not making dependencies clear. In fact, you’re obscuring them more than before. If you have a class like this…

    class DocumentCreator(IFileNamer fileNamer, IRepository repository)
    { ... }
    

    …you can see what the dependencies are. You can also easily mock those dependencies for unit testing, to ensure that you isolate the DocumentCreator and can know that any test failures are a result of its code rather than code in one of its dependencies.

    If, on the other hand, you do this…

    class DocumentCreator(IDependencyContainer container)
    { ... }
    

    …you’ve obscured the dependencies. You can’t know, without examining the internals of the class, that it requires an IFileNamer and an IRepository.

    Nor can you easily know what mocks you need to put in the container in order to test DocumentCreator. Mocking the IDependencyContainer won’t help you at all; your class will still fail in testing because the container won’t contain an IFileNamer and an IRepository, unless you examine the internals of the class to see that they’re required.

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

Sidebar

Related Questions

I need to display another external site's content into my site. Normally <iFrame> tag
Will there normally only be one instance of MainForm? I need to hold it
I have a dictionary that I normally access with a key, so I need
I have image intensive listviews that I need to GC, normally it would be
I need to insert rows rows into a database, then in another thread read
I need to redirect some output that would normally be printed to screen into
Whenever I have the need to design an API in Java, I normally start
Our repositories at work are generally CRUD, broken into one each of ICreatable ,
Normally when I need to have a list of ints/strings/etc. I create a list
I need to bulk load a large file into PostgreSQL. I would normally use

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.