import wvlet.airframe._ object MyApp { def main(args: Array[String]): Unit = { val design = newDesign .bind[HelloService].to[HelloServiceImpl] .bind[EmailService].to[EmailServiceImpl] val injector = design.newInjector val app = injector.get[MyApplication] app.run() } } trait HelloService { def sayHello(): Unit } class HelloServiceImpl extends HelloService { def sayHello(): Unit = { println("Hello from HelloServiceImpl") } } trait EmailService { def sendEmail(): Unit } class EmailServiceImpl extends EmailService { def sendEmail(): Unit = { println("Sending email from EmailServiceImpl") } } class MyApplication(helloService: HelloService, emailService: EmailService) { def run(): Unit = { helloService.sayHello() emailService.sendEmail() } }


上一篇:
下一篇:
切换中文