1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ZIOAppを使った、独自Environmentの実装方法

Posted at

EnvironmentがAnyだったり、あまり複雑でなければZIOAppDefaultを使えば良いですが、AService & BService & CService みたいに複雑になると、それを参照するのも手間だったりします。

デフォルトから異なるEnvironmentを使う場合、ZIOAppを継承して次のように実装できます。

import zio.*

object Main extends ZIOApp:
  override type Environment =
    AService & BService & CService & ... // 必要なサービスを列挙
  override val environmentTag: EnvironmentTag[Environment] =
    EnvironmentTag[Environment]
  override val bootstrap: RLayer[ZIOAppArgs, Environment] =
    AServiceImpl.layer ++ BServiceImpl.layer ++ CServiceImpl.layer ++ ... // サービス実装を列挙
  def run: RIO[Environment, Unit] =
    for _ <- MyService() // サービスを使った処理
    yield ()

参考

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?