Ninject kernel binding is like this:-
Create XML like Below:-
<module name="myXmlConfigurationModule">
<bind service="MyNamespace.IMyService, MyAssembly"
to="MyNamespace.MyServiceImplementation, MyAssembly" />
<bind service="MyNamespace.IMyOtherService, MyAssembly"
to="MyNamespace.MyOtherServiceImplementation, MyAssembly" />
</module>
Then Code:-
using Ninject;
enter code here
class ABC
{
public void CallingMethodUsingNinject()
{
private IKernel kernel= new StandardKernel();
kernel.Load("yourXmlFileName.xml");
bool ismodule = kernel.HasModule("myXmlConfigurationModule");//To Check The module
if(ismodule )
{
IMyService MyServiceImplementation = kernel.Get<IMyService>();
MyServiceImplementation.YourMethod();
}
}
}
Some you can face issue due to XML file property settings so need change your xml file settings.
Error activating IMyService No matching bindings are available, and the type is not self-bindable.
Solution:-Don't forget to set the Copy to Output
Directory property of this xml file to Copy if newer, so that it can be copied to the
output directory automatically
For More :-read https://www.packtpub.com/sites/default/files/9781782166207_Chapter_02.pdf