September 2018
Intermediate to advanced
398 pages
9h 43m
English
If you have many other configuration parameters to pass to your functions, it can be more convenient to put them in an ApplicationContext class and declare an implicit parameter of this class in your functions. The added benefit is that this context can not only store configuration parameters, but it can also hold references to commonly used service classes. This mechanism can effectively replace dependency injection frameworks, such as Spring or Guice, that you might have used with Java.
For instance, say that we have an application that implements a DataService trait. It has two methods that can load and save Product objects from a database, as shown in the following code:
case class Product(name: String
Read now
Unlock full access