Last active
October 26, 2022 00:07
-
-
Save 8bitreid/4edb0b1b29bbdf5284cf182caf626cc0 to your computer and use it in GitHub Desktop.
Simple ZLayer Example
This file contains 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
package example | |
import zio.{IO, Layer, Task, ULayer, ZIO, ZIOAppDefault, ZLayer} | |
// Main | |
object ZioApp extends ZIOAppDefault: | |
val app: Task[Unit] = | |
ZIO.serviceWithZIO[GreetingService](_.sayHello) | |
.provideLayer(GreetingModule.helloLayer) | |
def run: Task[Unit] = app | |
class GreetingService(): | |
def sayHello: Task[Unit] = ZIO.logInfo("Hello, from GreetingService!") | |
object GreetingModule: | |
val helloLayer: ULayer[GreetingService] = ZLayer.succeed(new GreetingService()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment