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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:14:52+00:00 2026-06-04T16:14:52+00:00

I was wondering how far I should take my IoC implementation in terms of

  • 0

I was wondering how far I should take my IoC implementation in terms of loosely coupling my application. I am using constructor injection in my MVC controller but wondered if I should also be resolving all my other dependencies in the controller instead of newing up objects. For example if I was to create a new User object within a controller method would I use?

var user = new User();
var user = myContainer.Resolve<IUser>();

I like the idea of breaking my dependency on User but is that going too far and could possible make my code harder to read?

  • 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-04T16:14:53+00:00Added an answer on June 4, 2026 at 4:14 pm

    This is a very good question, when you read and hear about DI it makes sense and this is the next natural conclusion.

    First Steven’s point is correct you should not pass the container around. If you need to construct IUser on the fly and it needs to be abstract you should rather inject an Abstract Factory.

    Sebastian also posted a good link.

    I actually wrote about this in an answer I posted here.

    The bottom section of the post:

    Not every object and dependency needs or should be dependency injected, first consider if what you are using is actually considered a dependency:

    What are dependencies?

    Application Configuration
    System Resources (Clock)
    Third Party Libraries
    Database
    WCF/Network Services
    External Systems (File/Email)
    

    Any of the above objects or collaborators can be out of your control and cause side effects and difference in behavior and make it hard to test. These are the times to consider an Abstraction (Class/Interface) and use DI.

    What are not dependencies, doesn’t really need DI?

    List
    MemoryStream
    Strings/Primitives
    Leaf Objects/Dto's
    

    So in your particular case it really depends on what happens when IUser is constructed also whether you actually need to substitute it with different implementations. If this is not the case and User has only simple types with no external dependencies or side effects just new it up.

    Consider what happens when you call new User(), look at the graph below, if it causes other objects to be created and looks like something in the graph below consider IoC.

    A cascading dependency object graph:

    Dependency graph

    In this example new on the object either requires or creates a whole bunch of other dependencies. It is most likely out of your control what those dependencies are or do.

    When your object is a simple dto it doesn’t suffer this problem and IoC is likely not so much required.

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

Sidebar

Related Questions

Wondering the pros and cons for MVC architecture in terms of web application development?
I'm using the Entity Framework for an ASP.NET Web Forms application and I'm wondering
I am wondering under what circumstances I should be putting application initialisation code in
I'm working on the back-end of my website and I'm wondering how far I
Im just wondering if I am pushing JSON too far? and if anyone has
wondering if some of you know what javascript framework facebook is using ? Thanks
I was wondering if using require() in node.js was the equivalent to lazy loading?
So far I have been using Twisted to simultaneously serve a lot of mobile
Going to develop a search engine. I'm wondering how my DDD should look. Sorting
I am wondering if there is any drawback for using forward declarations in all

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.