Comments (6)
このissueには複数の問題が混在してるような印象を受けます。
- 同じインターフェイスの違った実装への束縛をどのように扱うか?(ロボットの足問題)
- 束縛のバッティグ、上書きをどのように管理するか?
どうでしょうか、この認識であってるなら個別に考えたいと思います。まずは解決の切り口からと考えました。
from ray.di.
- 同じインターフェイスの違った実装への束縛をどのように扱うか?(ロボットの足問題)
- 束縛のバッティグ、上書きをどのように管理するか?
はい。言われて気づきましたが、この2つで合っていると思います。
from ray.di.
同じインターフェイスの違った実装への束縛をどのように扱うか?
これをロボットの足問題と言うのだそうです。
この問題はGuiceでも取り上げられてて @vectorxenon さんと同じ様にNamed Bindingで解決するのがいいかと思います。 https://code.google.com/p/google-guice/wiki/FrequentlyAskedQuestions
Javaのコードですが
class LegModule extends PrivateModule {
private final Class<? extends Annotation> annotation;
LegModule(Class<? extends Annotation> annotation) {
this.annotation = annotation;
}
@Override protected void configure() {
bind(Leg.class).annotatedWith(annotation).to(Leg.class);
expose(Leg.class).annotatedWith(annotation);
bindFoot();
}
abstract void bindFoot();
}
Injector injector = Guice.createInjector(
new LegModule(Left.class) {
@Override void bindFoot() {
bind(Foot.class).toInstance(new Foot("leftie"));
}
},
new LegModule(Right.class) {
@Override void bindFoot() {
bind(Foot.class).toInstance(new Foot("righty"));
}
});
束縛のバッティグ、上書きをどのように管理するか?
これはRay.Diでは拡張性を優先させて、意図的にルーズにしていています。
ベストプラクティスと言えるかですが、BEARで自分が実装しているのは
- アプリケーション単位でインジェクターを利用する場合は(想定された使い方です)Injector::create()で指定するモジュールを1つにする
- その1つのモジュール内でのみ上書きを扱う
BEAR.Packageはかなり大きな範囲で依存の上書きを行っていますが、これで問題なく管理できると思います。
ちなみにバインディングは echo $module
で確認できます。またモジュールのテストのためにAbstractModule
はArrayAccess
を実装していて束縛を確認できます。
from ray.di.
いろいろとありがとうございます。
束縛のバッティグ、上書きをどのように管理するか?
こちらの問題は提示して頂いた
- アプリケーション単位でインジェクターを利用する場合は(想定された使い方です)Injector::create()で指定するモジュールを1つにする
- その1つのモジュール内でのみ上書きを扱う
を試しに導入してみてスッキリしましたので、この方法でいこうかと思います。
from ray.di.
👍
from ray.di.
束縛のテストをかくのもいいと思います。
from ray.di.
Related Issues (20)
- XSS vulnerability may exist in Exception page HOT 1
- CLI実行時、リソースがコンパイル済みの場合に AssistedInjection が有効にならない HOT 3
- Error in toConstructor Injection HOT 4
- Problem in dynamic binding of class HOT 5
- The setter method can not be intercepted.
- Data files to PHP files
- Change data file text file to PHP file HOT 1
- Faster annotation reader HOT 1
- Refactor documentation HOT 1
- Injector receives an array of modules
- Multibindings
- Lazy instance injection
- Multiple interface bindings not possible in multibindings
- Support for multiple bindings for the same interface in different modules
- Support annotation in Multi bindings and Provider injection
- Codecov gets stuck HOT 1
- Failed to compile MediaQuery property
- Fresh containers reuse
- Implicit target binding issues
- Why do you use assert in production code? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ray.di.