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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:22:55+00:00 2026-06-16T03:22:55+00:00

Preface I feel like there is a real possibility to shoot yourself in the

  • 0

Preface

I feel like there is a real possibility to shoot yourself in the foot when working with DI frameworks.
(My framework of choice is ninject so I’ll be using that in my examples.)

I’m going to step back for a second and look at the reason DI frameworks exists:
To prevent having to do DI by hand

Right so, in the spirit of Ninjects documentation, lets say we have a Dojo that creates Samurais. These Samurais are given an IWeapon when they are made.

class Samurai{
    readonly IWeapon weapon;

    public Samurai(IWeapon weapon){
        this.weapon = weapon;
    }
}

Now it is my understanding that the Dojo would use Kernel.Get<IWeapon>() when it creates a Samurai.

Woah
Didn’t I just couple my Dojo to the Kernel?
Also… How is it supposed to get the Kernel: DI, a singleton, service location?

I feel like we just swiftly defeated the purpose of DI because now I’m dependent on my DI framework. What happens if ninja’s are defeated and ninject dies too?

Question

How do we use DI without coupling to a DI framework?

Postface

I’m sure this question has been asked before however I couldn’t find anything. Please use the comments to post relevant questions so that we can pool the knowledge to figure out the best solution.

  • 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-16T03:22:56+00:00Added an answer on June 16, 2026 at 3:22 am

    When doing Dependency Injection the trick is to have all your classes inject their dependencies through the constructor. This way you can let the Kernel build up a complete object graph for you from the root object.

    This ‘root object’ however, is something that has to be resolved directly by calling kernel.Get<HomeController>() (if HomeController is the root object). So somewhere in your application you will have to call kernel.Get. It’s impossible to go without.

    The trick is to minimize this to ideally a single line of code in the application and place this near the startup path. Probably close to the place where you registered your dependencies. The rest of the application stays oblivious to the use of any DI framework.

    There are even integration packages for Ninject and other containers that allow you to remove that single line of code depending on which application platform you use. ASP.NET MVC for instance has great extendibility points that allow you to plug in a ControllerFactory that allows you to let that factory call kernel.Get for you.

    How do we use DI without coupling to a DI framework?

    There will always be some coupling, but ideally this should only be the startup path. All other code should be oblivious to the use of a container. There will still be a assembly dependency, but this dependency will only exist in the startup project, and not in your business layer.

    look at the reason DI frameworks exists: To prevent having to do DI by
    hand

    To be more precise. DI helps making your application more maintainable. DI frameworks help making the startup path of your application (a.k.a. composition root) more maintainable.

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

Sidebar

Related Questions

Preface Feb 2015 If you are still using Entity Framework EDMX, please do yourself
I would like to preface by saying I guess there is no real tangible
Let me preface this by saying I feel like a moron. I have a
Preface: I'm know that in most cases using a volatile field won't yield any
PREFACE: I'm new to JavaScript and working through some tutorials, and I'm stuck here!
Preface I had a system-wide installation of Ipython which was working fine. However, when
Preface: First time really using JavaScript + jQuery, so my problem likely stems from
Preface: I know that there are high quality graph APIs available. I'm interested in
Preface: This question is about a project I am working on with a professor
Preface: I'm not sure what resources are. I need this form (which is working

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.