In my Dart application I'm using the MVP pattern and the angular-dart Dependency Injection library(angular-di).
In the example above, I cannot inject MyView or MyPresenter, as this is a circular dependency.
class MyView {
MyPresenter presenter;
MyView(this.presenter);
}
class MyPresenter {
MyView view;
MyPresenter(this.view);
}
The way I usually did this in Java with Guice was injecting a Factory, like:
class MyView {
MyPresenter presenter;
MyView(this.presenter);
}
class MyPresenter {
Factory<MyView> factoryView;
MyView view;
MyPresenter(this.factoryView) {
view = factoryView(this);
}
}
How do I accomplish this using angular-di? Is there possible to inject the factory without having to write the factory itself?
Angular 2 Dart
or
See also
Angular 1 Dart
You can bind a closure
the constructor should then look like
There is also a
toFactory:
but I guess DI will call the factory itself but I guesstoValue:
with a closure could work (not tried though).