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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T17:09:29+00:00 2026-05-13T17:09:29+00:00

I have a class that has dependencies that I’ve wired up with Ninject. public

  • 0

I have a class that has dependencies that I’ve wired up with Ninject.

public interface IFoo {}

public class MyObject {
    [Inject]
    IFoo myfoo;
}

In the real implementation I’m using property injection, but just to quickly illustrate, I’ll inject on the field. As I understand, instead of newing instances of MyObject, in order to get the dependencies to be properly injected, I need to use

kernel.Get<MyObject>()

The thing I’m stumbling on however is that MyObject will only be used in the context of a class library. The intention is for end applications to create their own modules and pass it into a kernel instance to hydrate. Given that, what’s generally the most pragmatic way to approach surfacing a generic instance of a Ninject kernel to my class library so that instances of MyObject (and other similar cases) can be hydrated?

My first inclination is some sort of factory that internalizes a singleton kernel–which the applications themselves have to hydrate/initialize by loading up a module.

So in RandomService.cs

var myKernel = NinjaFactory.Unleash();
var myobj = myKernel.Get<MyObject>();
myobj.foo();

Before I go too far down this path though, I need to do a sanity check to make sure that the thinking is sound or that there isn’t some obvious other thing that I’m missing. I’m obviously new to IoC and feel like I grok the basics, but not necessarily the best real world ways to use it.

  • 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-13T17:09:29+00:00Added an answer on May 13, 2026 at 5:09 pm

    I’m not sure that I understand all the details in your question, but I as far as I understand, you are asking how you can externalize the dependency on Ninject.

    It is possible to write DI-friendly libraries without ever referencing any particular DI Container (Ninject or anything else). This leaves the consumer of the library open to choose the DI Container of his or her liking (or not use a container at all). This approach is much preferred because it provides a greater degree of freedom.

    However, you should really favor Constructor Injection over Property Injection. Although Property Injection seems deceptively simple to implement, it’s actually quite difficult to get right.

    One of the great advantages of Constructor Injection is that you don’t need to put any attributes on the constructor because it structurally already carries all the information needed for a DI Container to correctly wire it up.

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

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer See the docs: your py2app.recipes package must contain a recipe… May 14, 2026 at 3:43 am
  • Editorial Team
    Editorial Team added an answer create unique index cars_unique_name on cars(name) May 14, 2026 at 3:43 am
  • Editorial Team
    Editorial Team added an answer So a few things. This is client side; the browser… May 14, 2026 at 3:43 am

Related Questions

I've been using manual constructor injection DI for a little bit now. One thing
I currently have a method within my class that has to call other methods,
Currently I have a class that looks like this: public class MyClass : IMyClass
I'm trying to use the MoqAutoMocker class that comes with StructureMap and I can't
Alright, after doing a ton of research and trying almost every managed CPP Redist

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.