So many of the examples for Ninject are very, very basic. It’s either just a controller, or they create the kernel and the object’s in a single function for demonstration purposes.
So for some reason I thought that you could just instantiate an object like normal, and Ninject would intercept that and work. For instance:
public class foo
{
public foo(IInjectable injected)
{
//stuff
}
}
Then somewhere in another class you could do:
var fooObject = new foo();
So am I supposed to use kernel.get instead?
Then, if I DO need to keep calling the kernel how do I pass that around to everything that needs it?
If you design your application well then there should only be only a single
Kernel.Getrequest happening in your application (often via something like likeNinject.MVC3). Usually that is where the root object of your application gets instantiated (for example MainViewModel of your application shell). All other types simply declare their dependencies in the constructor without knowing who is responsible for creating and managing their dependencies. Little exampleand the application builds itself up without accessing the kernel elsewhere.
See the factory extension for the
ToFactory()bit.