How do I bind Interface in Ninject only if it is not already bound? How do I bind Interface in Ninject only if it is not already bound? asp.net asp.net

How do I bind Interface in Ninject only if it is not already bound?


You have to make sure BaseModule is loaded after Client1Module:

   public class BaseModule: NinjectModule    {        public override void Load()        {            if (!Kernel.GetBindings(typeof(IService)).Any())            {                Bind<IService>().To<BasicService>();            }        }    }


If I assume I load the base Module first and then load the Client Module after I think I can just use

Rebind<IService>.To<FancyService>()

It seems to work