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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:19:44+00:00 2026-05-13T18:19:44+00:00

I am doing an MVC project with structuremap as an IOC container. We are

  • 0

I am doing an MVC project with structuremap as an IOC container. We are doing TDD, and I want to set up my dependencies so that its easy to work with, and so that its easy to test.

How should I best set up the graph of dependencies for the below fictional illustrated graph ?

  • ApplicationController
    • Controller
      • AuthenticationService
        • UserRepository

Do you inject the userrepository on the controller, and further from the in the authenticationservice? And what if the graph is deeper – will you not get a lot of dependencies starting on the controller?

If you have a dependency on you applicationcontroller, do you also inject that on the controller, and that way up on the base?

If I let the container resolve the instance somewhere in the middle of the graph, I would have to setup the container for testing? Is that a good thing to do, or best avoided?

Is there another way, that I am not seeing?

  • 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-13T18:19:44+00:00Added an answer on May 13, 2026 at 6:19 pm

    Your dependency graph looks fine. As illustrated, each class only has one dependency

    • ApplicationController depends on Controller
    • Controller depends on AuthenticationService
    • AuthenticationService depends on UserRepository

    I realize that this is a simplified view, and that your real production architecture will be much more complex, but the nice thing about DI (and Constructor Injection in particular) is that it makes violations of the Single Responsibility Principle so obvious.

    Whan a class starts getting too many dependencies, it’s a sign that you should refactor to an Aggregate Service.

    The final dependency graph may be huge, but each class only depends on a few abstractions, so from an architectural point of view, this is not a problem.

    You should never have to resolve the instance in the middle of the graph. Resolving is something that you do in the Composition Root, and (theoretically) only once.

    When it comes to unit testing, you shouldn’t have to use a DI Container at all.

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

Sidebar

Related Questions

Our current MVC project is set up to have ViewModels that encapsulate the data
Assume I have an ASP.NET MVC app that's not doing anything too fancy (no
When doing TDD , how to tell that's enough tests for this class /
My problem is quite simple - I think. I'm doing an ASP.NET MVC project.
In my MVC project indide one of my views I have some JQuery that
Okay still fighting with doing some SqlCacheDependecy in my Asp.net MVC application I got
If you are using ASP.NET MVC how are you doing grid display? Rolled your
Am I doing something wrong is this a known issue with the ASP.NET MVC
I am trying to wrap my head around doing validation in a MVC scenario.
Doing odd/even styling with jQuery is pretty easy: $(function() { $(.oddeven tbody tr:odd).addClass(odd); $(.oddeven

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.