DeftJS is the first time I have taken a serious look at dependency injection, so I think the following question might stem from a slight misunderstanding of what Dependency Injection (normally) is.
Does DeftJS provide any way for injecting the dependencies after an object has been created? Specifically, at a certain point when the object requests the object (i.e. creates it). I have now discovered that this is not typical Dependency Injection behaviour because normally the dependency is resolved before the object is created. However, in some situations the dependency cannot be resolved until the first object has been created (for example, if the dependency is an ExtJS DropTarget, which needs the DOM element in the constructor). Here is some example code:
Ext.define('MyDropTarget', {
inject: ['dropTarget'],
constructor: function() {
this.dropTarget.create(this.el.dom); // in reality this may need to be inside a 'boxready' listener
}
});
From what I have seen I don't think DeftJS provides behaviour like this, is there anything I am missing?
The closest I can get is using a factory function, since that has access to the object that was created, but in some cases the dependency can only be resolved after some period of time. Even then, using this method wouldn't be desirable because it would move this logic into the factory function, but it might be more appropriate in the object itself.
From my research it seems like this isn't pure dependency injection, because some of the dependency remains in the fact that we have to create the dependency. Could something like this be added to DeftJS?