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 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

I have a MVC Project. I have questions in a database that I want
Assume I have an ASP.NET MVC app that's not doing anything too fancy (no
I noticed that when I installed StructureMap from NuGet into my ASP.NET MVC3 project,
I have an ASP.NET MVC project that works fine on my local machine (no
My problem is quite simple - I think. I'm doing an ASP.NET MVC project.
I want to generate Canonical url´s at my ASP.NET MVC project. I did a
I have situation like this: I am doing my own mvc project in visual
In my MVC project indide one of my views I have some JQuery that
I'm working with an MVC project, trying to implement IoC and DI. Both these
im doing my first asp.net MVC project here, i need to be able to

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.