I have a module that I load it by Kernel when my application starts with the following code:
IKernel kernel = new StandardKernel();
kernel.Load("*.dll");
But in some cases I don’t want to place the module assembly in bin folder and don’t use that module and it corresponding features. Then I have properties in my consumer class that use [Inject] attribute. I want to Ninject return null for these properties when it doesn’t find it’s module.
By default this code throw an exception if NInject fails to find a dependency.
To solve this, simply add the
Optionalattribute to the property: