Last active
June 4, 2020 05:23
-
-
Save adamw/71732b86ecf89689d0cabcabca28f615 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import zio._ | |
object Main extends App { | |
override def run(args: List[String]): ZIO[zio.ZEnv, Nothing, ExitCode] = { | |
// using the UserRegistration's method accessor to construct the program, | |
// outside of a layer definition | |
val program: ZIO[UserRegistration, Throwable, User] = | |
UserRegistration.register(User("adam", "[email protected]")) | |
// composing layers to create a DB instance | |
val dbLayer: ZLayer[Any, Throwable, DB] = | |
ZLayer.succeed(DBConfig("jdbc://localhost")) >>> | |
ConnectionPoolIntegration.live >>> | |
DB.liveRelationalDB | |
// composing layers to create a UserRegistration instance | |
val userRegistrationLayer: ZLayer[Any, Throwable, UserRegistration] = | |
((dbLayer >>> UserModel.live) ++ UserNotifier.live) >>> UserRegistration.live | |
// creating the complete application description | |
program | |
.provideLayer(userRegistrationLayer) | |
.catchAll(t => ZIO.succeed(t.printStackTrace()).map(_ => ExitCode.failure)) | |
.map { u => | |
println(s"Registered user: $u (layers)") | |
ExitCode.success | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment