How to add new object to track in Ninject after Application_Started?
Is it possible to add a new object that Ninject should be responsible for (lifetime, injection etc.) in an ASP.NET application after the Application_Started
event开发者_如何学Python is fired?
My application needs to dynamically designate objects that should be tracked well after the application is started
If you have access to the Kernel
object created at Application_Start
either by a static reference or [preferably] by use of a Common Service Locator, you should be able to call Bind<T>()
on the object to update the context.
I haven't personally tried this, but it does comply with the class structure.
(Some of this addresses the other answer more than your question, but hope it helps overall) You don't really call Bind<T>()
on object instances, you do that to register bindings which are then used in either resolving new instances via Kernel.Get<T>()
or using Kernel.Inject(@object)
to inject [typically properties only (as you're not constructing)] into an object not created under the control of Ninject.
While Inject
ed objects will be activated etc., their scoping etc. doesnt always work in the same way. Perhaps you can expand on exactly what specific services you expect to gain other than property injection to clarify? (See the cache and collect opus for details of lifetime management)
精彩评论