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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:13:09+00:00 2026-06-15T18:13:09+00:00

I’m currently learning Ninject and dependency injection and in my current set-up I’m passing

  • 0

I’m currently learning Ninject and dependency injection and in my current set-up I’m passing IKernel into places so other classes can instantiate certain classes or grab factory instances.

Currently I’ve got my factories bound as singletons, and passing IKernel into an object then doing _kernel.Get<ISomethingFactory>().CreateSomething() seems like it could be a bit of a code-smell and simply turning Ninject into a glorified service locator.

Also, my factories are being passed IKernel so they can resolve the bound implementation of the respective interface they create.

My questions are:

  1. Is it permissible for factories to function in this way, or should the factory simply instantiate the concrete type itself?

  2. Instead of passing IKernel all over the place, should I be favouring passing the factories / other services through the constructor?

  • 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-15T18:13:10+00:00Added an answer on June 15, 2026 at 6:13 pm

    I prefer not to.. but that’s just me.

    Also, I don’t roll my own factories.. I use Ninjects Factories extension. You can find it here:

    https://github.com/ninject/ninject.extensions.factory

    Basically, you create your bindings like normal, but then you create interfaces for factories (assuming WinForms here):

    public interface IMainFormFactory {
        frmLogin CreateLoginForm();
        frmSettings CreateSettingsForm();
        IRepository<MainFormModel> CreateMainFormRepository();
    }
    

    ..and bind it with the ToFactory extension:

    using Ninject.Factories; // can't quite remember namespace at the moment
    
    public class FactoryModule : NinjectModule {
        protected override void Load() {
            Bind<IMainFormFactory>().ToFactory();
        }
    }
    

    The factories extension doesn’t need you to define a concrete implementation of this interface.. it already knows what to do with these objects based on bindings you’ve provided (and will still instantiate anything you haven’t defined a binding for.. such as forms. Behind the scenes it creates a manager that implements this interface for you).

    So then, you can do things like this:

    private readonly IMainFormFactory _factory;
    
    public frmMainForm(IMainFormFactory factory) {
        _factory = factory;
    }
    
    public void btnSettings_Click(object sender, EventArgs e) {
        // show the settings form..
        var settingsForm = _factory.CreateSettingsForm();
        settingsForm.ShowDialog();
    }
    

    ..then in frmSettings it will inject as well:

    public frmSettings(ISettingsFormFactory factory) {
        // as above except for ISettingsFactory
    }
    

    ..this is how I choose to do things. Perhaps others have better ideas (I’d be interested in hearing them too!).

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am currently running into a problem where an element is coming back from
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I want use html5's new tag to play a wav file (currently only supported
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
Does anyone know how can I replace this 2 symbol below from the string

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.