Skip to content

Instantly share code, notes, and snippets.

@8bitreid
Last active October 26, 2022 00:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 8bitreid/4edb0b1b29bbdf5284cf182caf626cc0 to your computer and use it in GitHub Desktop.
Save 8bitreid/4edb0b1b29bbdf5284cf182caf626cc0 to your computer and use it in GitHub Desktop.
Simple ZLayer Example
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