8

I'm currently working with a codebase that requires an explicit parameter to have implicit scope for parts of its implementation:

class UsesAkka(system: ActorSystem) {
   implicit val systemImplicit = system

   // code using implicit ActorSystem ...
}

I have two questions:

  1. Is there a neater way to 'promote' an explicit parameter to implicit scope without affecting the signature of the class?

  2. Is the general recommendation to commit to always importing certain types through implicit parameter lists, like ActorSystem for an Akka application?

Semantically speaking, I feel there's a case where one type's explicit dependency may be another type's implicit dependency, but flipping the implicit switch appears to have a systemic effect on the entire codebase.

Lawrence Wagerfield
  • 6,471
  • 5
  • 42
  • 84
  • 1
    It seems to be that having `system: ActorSystem` **not** be an implicit doesn't have any benefit. You can always override an implicit parameter. For your questions, I would say **no** and **maybe**. – dyross Jun 10 '14 at 02:04

1 Answers1

1

Why don't you make systemImplicit private ?

class UsesAkka(system: ActorSystem) {
   private implicit val systemImplicit = system
// ^^^^^^^

   // ...
}

This way, you would not change the signature of UsesAkka.

Alex Archambault
  • 985
  • 1
  • 8
  • 16