GithubHelp home page GithubHelp logo

Comments (6)

koriym avatar koriym commented on June 15, 2024

このissueには複数の問題が混在してるような印象を受けます。

  • 同じインターフェイスの違った実装への束縛をどのように扱うか?(ロボットの足問題)
  • 束縛のバッティグ、上書きをどのように管理するか?

どうでしょうか、この認識であってるなら個別に考えたいと思います。まずは解決の切り口からと考えました。

from ray.di.

yukikaoru avatar yukikaoru commented on June 15, 2024
  • 同じインターフェイスの違った実装への束縛をどのように扱うか?(ロボットの足問題)
  • 束縛のバッティグ、上書きをどのように管理するか?

はい。言われて気づきましたが、この2つで合っていると思います。

from ray.di.

koriym avatar koriym commented on June 15, 2024

同じインターフェイスの違った実装への束縛をどのように扱うか?

これをロボットの足問題と言うのだそうです。

この問題は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で確認できます。またモジュールのテストのためにAbstractModuleArrayAccessを実装していて束縛を確認できます。

from ray.di.

yukikaoru avatar yukikaoru commented on June 15, 2024

いろいろとありがとうございます。

束縛のバッティグ、上書きをどのように管理するか?

こちらの問題は提示して頂いた

  • アプリケーション単位でインジェクターを利用する場合は(想定された使い方です)Injector::create()で指定するモジュールを1つにする
  • その1つのモジュール内でのみ上書きを扱う

を試しに導入してみてスッキリしましたので、この方法でいこうかと思います。

from ray.di.

koriym avatar koriym commented on June 15, 2024

👍

from ray.di.

koriym avatar koriym commented on June 15, 2024

束縛のテストをかくのもいいと思います。

from ray.di.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.