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 ?
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:
and also modify binding: