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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:38:08+00:00 2026-06-01T17:38:08+00:00

Using Ninject i would like to rebind one method to another implementation is that

  • 0

Using Ninject i would like to rebind one method to another implementation is that possible ?

I will elaborate, I have this interface with two different implementations:

public interface IPersonFacade
{
  List<string> GetPeople();
  string GetName();
}

public class PersonFacade:IPersonFacade
{
  //Implement Interface fetching data from a db.
}

public class PersonFacadeStub:IPersonFacade
{
  //Implement Interface with some static data
}

I am using the Ninject mvc extension and have my NinjectModule implementation:

public class ServiceModule:NinjectModule
{   
  public override void Load()
  {
    Bind<IPersonFacade>().To<PersonFacade>();
  }
}

So back to my question, is it possible to rebind the method GetPeople() so it uses the implementation from the PersonFacadeStub but IPersonFacade keeps using the GetName from the PersonFacade ?

  • 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-01T17:38:09+00:00Added an answer on June 1, 2026 at 5:38 pm

    I don’t think it is possible. NInject like any other DI container manages types, not methods. If you want to use different types for different methods of the same interface pattern Composite may help:

    public class CompositePersonFacade : IPersonFacade
    {
        private readonly IPersonFacade realFacade;
        private readonly IPersonFacade stubFacade;
    
        public CompositePersonFacade(IPersonFacade realFacade, IPersonFacade stubFacade)
        {
            this.realFacade = realFacade;
            this.stubFacade = stubFacade;
        }
    
        public List<string> GetPeople()
        {
            return stubFacade.GetPeople();
        }
    
        public string GetName()
        {
            return realFacade.GetName();
        }
    }
    

    and also modify binding:

    Bind<IPersonFacade>().To<CompositePersonFacade>()
        .WithConstructorArgument("realFacade", 
                      context => context.Kernel.Get<PersonFacade>())
        .WithConstructorArgument("stubFacade", 
                      context => context.Kernel.Get<PersonFacadeStub>());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have set up a NInject (using version 1.5) binding like this: Bind<ISessionFactory>().ToMethod<ISessionFactory>(ctx =>
I have the following implementation and would like some feedback as to whether it
Using a DI container (in this case, Ninject ) is it possible - -
I want to map DbConnection to an un-opened SqlConnection using Ninject . This is
In my application, I would like to load Assemblies that reside on a network
I have the following code in my Ninject module: this.BindFilter<PermitFilter>(FilterScope.Controller, 0) .WhenControllerHas<PermitAttribute>() .WithConstructorArgumentFromControllerAttribute<PermitAttribute>( permissions,
I have been using Ninject as the IOC for an XNA project, and was
I would like to have in my repository as tagged or submodules the different
Possible Duplicate: Using IoC for Unit Testing I think I do have a Problem
I have a structure like this WebUI project - controllers, views Framework project- repositories,service

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.