AV
Size: a a a
AV
Y
AD
Y
Y
import cats.syntax.semigroup._
import cats.effect.{ExitCode, IO, IOApp}
import distage.{DIKey, GCMode, Injector}
trait AppEntrypoint {
def run: IO[Unit]
}
object Main extends App {
def run(args: List[String]): IO[ExitCode] = {
// `distage.Module` has a Monoid instance
val myModules = ProgramModule[IO] |+| SyncInterpreters[IO]
val plan = Injector().plan(myModules, GCMode(DIKey.get[AppEntrypoint]))
for {
// resolveImportsF can effectfully add missing instances to an existing plan
// (You can also create instances effectfully inside `ModuleDef` via `make[_].fromEffect` bindings)
newPlan <- plan.resolveImportsF[IO] {
case i if i.target == DIKey.get[DBConnection] =>
DBConnection.create[IO]
}
// `produceF` specifies an Effect to run in.
// Effects used in Resource and Effect Bindings
// should match the effect in `produceF`
_ <- Injector().produceF[IO](newPlan).use {
classes =>
classes.get[AppEntrypoint].run
}
} yield ExitCode.Success
}
}
AV
Y
AV
AV
AV
.from
is not required for concrete classes AV
Y
AV
AV
AV
AV
Y
AV
AV
AV