[feature] DI in Editors
See original GitHub issueI’m submitting a feature request
- Browser: all
- Language: TypeScript
Current behavior:
Library/Custom Editors cannot use Aurelia’s DI. External services, such as the i18n
library, must be injected into the users view model and then added to the columnDef.params
object just so the grid editor can use that service. Then, the Editors
have to perform null checks to ensure the user sets the service on the params
object. This means that our Editors
using i18n
(singleSelectEditor
, multipleSelectEditor
and dateTimeEditor
) are dependent on the user passing in the service.
Expected/desired behavior:
Library/Custom Editors support Aurelia’s DI. To implement this we need to loop through the columnDefinitions
during the AureliaCustomElement
binding and reset the columnDef.editor
property with a wrapper such as:
for (let c of this.columnDefinitions) {
if (c.editor) {
c.editor = Factory.of(c.editor).get(this.container)
}
}
- What is the motivation / use case for changing the behavior?
I opened this issue for discussion to get your feedback. I have no need for it right now, but I wonder if it will make for a cleaner API instead of using the
params
property where other values are dumped.
Pros
- Users do not have to inject services into their view model 2 Reduce dependencies for the external service from 2 classes to 1 (2 classes being the Editor and the View Model)
Cons
- We need to take dependencies on the Aurelia’s
Container
andFactory
resolver in theAureliaCustomElement
(unless you could think of a better way)
Issue Analytics
- State:
- Created 6 years ago
- Comments:13 (7 by maintainers)
Top GitHub Comments
yes I would use the
editor
property. Nothing should change for the user. But I will work on a PR so we can see it in practiceClosed by PR #33