Navigation Menu

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

Dependency Injection support for Polymer #18875

Closed
DartBot opened this issue May 19, 2014 · 15 comments
Closed

Dependency Injection support for Polymer #18875

DartBot opened this issue May 19, 2014 · 15 comments
Assignees
Labels
area-pkg Used for miscellaneous pkg/ packages not associated with specific area- teams. P3 A lower priority bug or feature request type-enhancement A request for a change that isn't a bug

Comments

@DartBot
Copy link

DartBot commented May 19, 2014

This issue was originally filed by @zoechi


What steps will clearly show the issue / need for enhancement?
1.
Es wäre toll wenn Polymer DI direkt unterstützen würde so in der Art wie bei Angular.

2.
3.

What is the current output?

What would you like to see instead?

What version of the product are you using? On what operating system?

Please provide any additional information below.

@DartBot
Copy link
Author

DartBot commented May 19, 2014

This comment was originally written by @zoechi


see also https://plus.google.com/+SethLadd/posts/VijLdhGhtzg

@dgrove
Copy link
Contributor

dgrove commented May 19, 2014

Set owner to @justinfagnani.
Added Type-Enhancement, Area-Polymer, Triaged labels.

@justinfagnani
Copy link
Contributor

I have an implementation of this based on events, so it has the potential to be framework, DI container, and maybe even language agnostic. I should be able to publish the code very soon.

The lifecycle is quite different than Angular - we can't do constructor injection, but in the constructor, read(), and enteredView() we can fire dependency request events.


Changed the title to: "Dependency Injection support for Polymer".

@sigmundch
Copy link
Member

FYI, there was some discussion long ago about adding a second argument in document.registerElement to have an argument provider passed there as well (see https://code.google.com/p/dart/issues/detail?id=15804#c1).

@justinfagnani
Copy link
Contributor

True, and I've talked to Dimitri a lot about adding something like this. I've come to think that constructor injection might not be the best thing for elements though. So many dependencies are context-dependent, that being able to resolve them on enteredView() is pretty key, and we might want to encourage that over constructor injection, even if constructor injection was available.

Also, consider that for testing of elements we'll have to call the lifecycle methods anyway to ensure the element is set up (we might want to consider if there are useful helpers for element tests). Resolving dependencies outside the constructor might not actually add a lot of complexity to tests given that.

@sigmundch
Copy link
Member

Oh, I was under the impression that we didn't wanted to do any injection that couldn't be done in constructors, to make sure DI is still easy to reason about and to make sure we can statically generate equivalent code.

Would that still be the case even if we inject on 'enteredView'?

@justinfagnani
Copy link
Contributor

Looking at the use cases for DI in Angular, I just don't think that we have as many fixed dependencies, and that enteredView(), or on-demand, is generally a more appropriate place to resolve a lot of these things.

Totally non-scientifically, here's what I see commonly injected in Angular:

 * Scope - we don't have this
 * Element - we have this
 * Other Directives - we don't have directives, but there is behaviors.dart. The big difference with behaviors is that they can come and go dynamically as the DOM changes, so they're not fixed. I'm thinking of other avenues for behaviors and elements to collaborate.
 * Parser and Interpolate. I'm not sure we have the same use cases, but each element already has access to its binding delegate via syntax, and other hooks like instanceTemplate()

Services are something that could be fixed and appropriate for constructor injection, but sometimes polymer services are created as custom elements themselves, which are meant to be found via the document, which could make them context dependent too.

I don't think dependencies being more dynamic effects code-generation. What we generate is the module/injector code so that it doesn't use reflection. That will still work. Also, an event-based dependency resolution system would be DI container agnostic.

In terms of reasoning about DI... well, I think we could actually make things a bit easier to understand by resolving dependencies later. Documents are mutable, and fixing some things on element creation, while others are subject to the changing document structure could lead to confusing situations.

Last thought for now: Polymer and custom elements don't speak much to how models and UI patterns like MV* are used. If you use custom elements like views, and separate out controllers, the controllers can use very standard DI.

@DartBot
Copy link
Author

DartBot commented May 20, 2014

This comment was originally written by @zoechi


This seems all very promising!

I think it could be easier for code generation to have an 'inject(Typex argx, ...)` callback method to be called by the DI container that provides the arguments listed in the method signature, just as it is normally done with the constructor.

I haven't seen how the syntax/semantic would look like the event-based approach though.

@jmesserly
Copy link

Removed Area-Polymer label.
Added Pkg-Polymer, Area-Pkg labels.

@sigmundch
Copy link
Member

Added this to the Later milestone.
Added Priority-Low label.

@sigmundch
Copy link
Member

Added Polymer-P-2 label.

@sigmundch
Copy link
Member

Removed this from the Later milestone.

@sigmundch
Copy link
Member

Removed Polymer-P-2 label.
Added Polymer-Milestone-Later label.

@sigmundch
Copy link
Member

Removed Polymer-Milestone-Later label.
Added PolymerMilestone-Later label.

@DartBot DartBot added Type-Enhancement area-pkg Used for miscellaneous pkg/ packages not associated with specific area- teams. P3 A lower priority bug or feature request labels Jul 9, 2014
@DartBot
Copy link
Author

DartBot commented Jun 5, 2015

This issue has been moved to dart-archive/polymer-dart#186.

@DartBot DartBot closed this as completed Jun 5, 2015
@kevmoo kevmoo added type-enhancement A request for a change that isn't a bug and removed triaged labels Mar 1, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-pkg Used for miscellaneous pkg/ packages not associated with specific area- teams. P3 A lower priority bug or feature request type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

6 participants