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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T15:31:47+00:00 2026-05-12T15:31:47+00:00

I have a solution with two relevant (to this question) projects, and a few

  • 0

I have a solution with two relevant (to this question) projects, and a few others;

  1. Class library with functionality used by several other projects.
  2. ASP.NET MVC application.

My question is basically where I should do IoC with Ninject 2, considering…

  • The class library needs some DI love, among other things in the repository classes which need web request specific session objects (think Unit of Work).
  • The MVC app needs DI since with Ninject 2 you basically inherit from NinjectHttpApplication.
  • Unit tests for the class library need to be aware of this to inject a different set of repositories.
  • Unit tests for the web app need to be injected for the same reason.

I have painted myself into a mental corner here, because I only saw three options to begin with. DI in the class library, DI in the web app, or both, but there are problems with each:

  • I can’t do DI only in the class library since the MVC app needs to inherit from NinjectHttpApplication to begin with.
  • I can’t do DI only in the MVC app – the class library is used by other libraries, after all, and the MVC app shouldn’t know too much about the internals of the library anyway.
  • I guess this is the only way out I can see: Independent IoC for both projects. The class library and the MVC app each have their own IoC setup and do DI for their stuff without really caring about each other.

Does anyone have some “best practices” or guidelines on how to do something like this? I can’t imagine I’m the first person to end up in this situation, and it would sure be nice to know what the “proper” way to do this is…

Thanks!

  • 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-12T15:31:47+00:00Added an answer on May 12, 2026 at 3:31 pm

    I don’t know NInject, but unless it works vastly different than Windsor, StructureMap etc. the answers tend to stay the same, as there are some common DI patterns. With that in mind:

    The first thing to realize is that DI isn’t tied to a particular framework such as NInject or Windsor. It is a set of techniques and design patterns to follow. You can do DI manually using so-called Poor Man’s DI, but obviously it gets much better with a DI Container.

    Why is this relevant? It is relevant because once you realize this, the corollary is that the vast majority of your application’s code should have no knowledge of the DI Container whatsover.

    So where do you use the DI Container? It should only be used in a Composition Root, which in your case would correspond to Global.asax. You can read a bit more about this in this SO answer – although that question is about Windsor, the principle remains the same.

    How about your unit tests then? They should be completely ignorant of the DI Container as well. See this other SO answer for more details.

    DI can be achieved in your library with copious use of Constructor Injection. You don’t need to reference any DI Container to do that, but it makes life a lot easier if you use a DI Container to resolve all dependencies from the Composition Root.

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

Sidebar

Ask A Question

Stats

  • Questions 253k
  • Answers 253k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Try using OPENROWSET, as in this question. I thought I… May 13, 2026 at 9:59 am
  • Editorial Team
    Editorial Team added an answer Don't you have to set the Layoutmanager for the JPanel?… May 13, 2026 at 9:59 am
  • Editorial Team
    Editorial Team added an answer I found a solution for download. (Windows version) The readme… May 13, 2026 at 9:59 am

Related Questions

Solved Problem: to show external code dependency by submodules: Thanks to VonC ! Current
I have a page with a table of stuff and I need to allow
This is my second question about this topic, the original question can be found
I've just written a small XBox 360 Wireless Controller managed interface that basically wraps

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.