I'm new to Ninject (and DI in general).
I understand how the kernel loads modules, and the code I've written thus far tends to have a single line:
myKernel.Get<MyApp>()
which constructs everything I need from the bindings in my module. If there's a requirement for new instances post initialization, these are taken care of by factories that I bind for initialization. Up to now, the factories have been free of any ninject dependencies, simply newing up objects on demand.
Now I have reached a point that I need to think about object creation after initialization and my own factory pattern is not cutting it any more. This would be to support a pub/sub interface for (remote) clients. With every new connection to my server, I would like to create new IClient
instances according to a set of bindings defined in a ninject module. Does this mean that the factory I pass in at initialization has to have its own kernel (or a ref to the main kernel)? Where would CommonServiceLocator feature in this. Is CSL necessary?
Before I travel too far down dead-ends, I thought it would be best to ask here about how others might approach this problem.
ToFactory()
call? – Chatterton