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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T11:53:10+00:00 2026-06-16T11:53:10+00:00

I’m looking at this tutorial, but not quite understanding how to create a factory

  • 0

I’m looking at this tutorial, but not quite understanding how to create a factory that can provide me separate implementations of an interface.

http://stefanoricciardi.com/2011/01/21/ninject-mini-tutorial-part-1/

public class IJob {
  ...
}

public class JobImpl1 : IJob {
  ...
}

public class JobImpl2 : IJob {
  ...
}

using (IKernel kernel = new StandardKernel()) {
    kernel.Bind<IJob>().To<JobImpl2>(); 
    var job = kernel.Get<IJob>();
}

My goal is to make a factory class that wraps this Ninject Kernel so I can provide different implementations of my IJob interface depending on whether I’m in a unit test environment vs a live environment. However, I also want to keep the Ninject hidden inside the factory wrapper so that the rest of the code will not depend on Ninject.

  • 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-16T11:53:12+00:00Added an answer on June 16, 2026 at 11:53 am

    There is a separate extension Ninject.Extensions.Factory that allows you to generate Abstract Factory implementation on fly based on interface

    Kernel configuration

    var kernel = new StandardKernel();
    
    // wire concrete implementation to abstraction/interface
    kernel.Bind<IJob>().To<JobImpl1>()
        .NamedLikeFactoryMethod<IJob, IJobFactory>(f => f.GetJob());
    
    // configure IJobFactory to be Abstract Factory
    // that will include kernel and act according to kernel configuration    
    kernel.Bind<IJobFactory>().ToFactory();
    

    Resolve Abstract Factory at runtime using kernel

    // get an instance of Abstract Factory
    var abstractFactory = kernel.Get<IJobFactory>();
    
    // resolve dependency using Abstract Factory
    var job = abstractFactory.GetJob()
    

    Abstract Factory interface

    public interface IJobFactory
    {
        IJobFactory GetJob();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a jquery bug and I've been looking for hours now, I can't
I have a French site that I want to parse, but am running into
This could be a duplicate question, but I have no idea what search terms
I know there's a lot of other questions out there that deal with this
Does anyone know how can I replace this 2 symbol below from the string
I need a function that will clean a strings' special characters. I do NOT
I'm not entirely sure how I managed to jack this up. http://pretty-senshi.com If you
I'm trying to create an if statement in PHP that prevents a single post
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

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.