Lawrence Wagerfield
Lawrence Wagerfield

Reputation: 6611

Dealing with explicit parameters required by inner implicit parameter lists

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.

Upvotes: 8

Views: 99

Answers (1)

Alex Archambault
Alex Archambault

Reputation: 985

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.

Upvotes: 1

Related Questions