Understanding Service Dependency Management to Avoid Leaking Implementation Details

Basic quesition number two million - in the docs it says

We want to avoid leaking these implementation details into the service interface.


I assume that means if I have. a service that depends on a service, its better to "require" that service in the building of the layer, rather than the actual "function" that is inside of the service.

something like

Layer.effect(MyService, Effect.gen(function* () {
  const myOtherService = yield* MyOtherService

   return {
     doThing() {
        yield* myOtherService
        ....rest of code
      }
    }


Assuming I have this correct, what is "bad" about putting the yield of MyOtherService inside of the doThing function? The docs say "leaking" implementation details but i guess i'm just not seeing it doing anything poorly? Maybe this example is too trival and this problem is more seen in larger dependency graphs?
Was this page helpful?