Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- trait Config {
- val dbType: String
- val serviceEndpoint: String
- }
- class ProdConfig extends Config {
- val dbType = "Production"
- val serviceEndpoint = "linkedin.com"
- }
- trait Controller
- trait Service
- class Controller1(serviceEndpoint: String, service1: Service1)
- extends Controller {
- println(serviceEndpoint)
- }
- class Controller2(serviceEndpoint: String, service1: Service1, service2: Service2)
- extends Controller {
- println(serviceEndpoint)
- }
- class Service1(dbType: String) extends Service {
- println(dbType)
- }
- class Service2(dbType: String) extends Service {
- println(dbType)
- }
- def service1 = Reader((c: Config) => new Service1(c.dbType))
- def service2 = Reader((c: Config) => new Service2(c.dbType))
- def controller1(s: Service1) = Reader[Config, Controller1] {
- c => new Controller1(c.serviceEndpoint, s)
- }
- def controller2(s1: Service1, s2: Service2) = Reader[Config, Controller2] {
- c => new Controller2(c.serviceEndpoint, s1, s2)
- }
- println("Faking a context.register call")
- val cfg = new ProdConfig
- val controllers = Reader[Config, (Controller1, Controller2)] {
- c => for {
- s1 <- service1
- s2 <- service2
- c1 <- controller1(s1)
- c2 <- controller2(s1,s2)
- } yield(c1, c2)
- }
- println(controllers.run(cfg))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement