Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow @Inject() decorator on fields and set accessors #71

Open
4 tasks
DanielSchaffer opened this issue Apr 18, 2020 · 0 comments
Open
4 tasks

Allow @Inject() decorator on fields and set accessors #71

DanielSchaffer opened this issue Apr 18, 2020 · 0 comments
Assignees
Labels
@dandi/core feature New feature or request
Milestone

Comments

@DanielSchaffer
Copy link
Contributor

This feature implements "deferred" injection by allowing the @Inject() decorator to be used on fields and properties with set accessors. This will effectively allow "seamless" circular dependencies when they are needed, since properties and fields not defined in the constructor can be injected after the host class is instantiated.

Acceptance Criteria

  • @Inject() decorator is updated to be both a param and property decorator (note: hybrid decorators can be defined by using an intersection type of the decorator types - ParamDecorator & PropertyDecorator
  • injector/generator injects fields/properties after the "initial" hierarchy is instantiated. Constructor dependencies are recursed, so injectable classes will basically need to have a second recursion tree for the properties after the instance is created
  • @Inject() throws an error when used on a property with no set accessor
  • since fields will need to be set outside the constructor, this will likely not work on readonly fields - in this case, @Inject() should throw for those too

To Discuss

  • Is this a bad idea? E.g. will it enable/encourage bad practices?
  • Are there cases when fields/properties will not be able to be set before exposing the instance to the consumer? If so, does the consumer need to be notified of when the values are available?
@DanielSchaffer DanielSchaffer added feature New feature or request @dandi/core labels Apr 18, 2020
@DanielSchaffer DanielSchaffer added this to the v1.0.0 milestone Apr 18, 2020
@brianweyer brianweyer self-assigned this Apr 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@dandi/core feature New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants