2

I have created simple own type: type MyEnv = ZEnv with Clock with MyRepository

and have Main method:

object Main extends App {
  lazy val live: ZLayer[Any, Nothing, Has[MyRepository.Service]] = ZLayer.succeed(LiveMyRepository.repository)

  val routes = Router[AppTask](
    "/" -> MyRoutes.routes
  ).orNotFound

  val server: ZIO[MyEnv, Throwable, Unit] = ZIO.runtime[MyEnv]
    .flatMap {
      implicit rts =>
        BlazeServerBuilder[AppTask]
          .bindHttp(config.port, config.host)
          .withHttpApp(routes)
          .serve
          .compile
          .drain
    }

  def run(args: List[String]): ZIO[ZEnv, Nothing, Int] = {
    server.provideCustomLayer(live) foldM(
      err => putStrLn(s"Execution failed with: $err") *> IO.succeed(1),
      _ => IO.succeed(0))
  }

But I got compilation error in run method:

Error:(33, 30) Cannot prove that zio.ZEnv with zio.Has[my.repositories.MyRepository.Service] <:< my.application.Environment.MyEnv.
    server.provideCustomLayer(live) foldM(

I do not know how to fix it. Also I have error connected with implicit in server.provideCustomLayer(live):

No parameter found for implicits ev: ZEnv with Has[MyRepository.Service] <:< MyEnv

I tried to find a solution, but ZIO documentation is so useless and there is no good solution in other places.

Developus
  • 1,400
  • 2
  • 14
  • 50

0 Answers0