implicit val reader: Reader[ApplicationConfig, FooService[Task]] = genericReader
and then when we finally instantiate the whole application with F = Task
this instance should be found. If we need anything else than F = Task
we need to provide other instances
collect
all the elements of a given type and check if the list has size 1 if you want to check that a singleton exists
import cats.Eval
import cats.data.Reader
import cats.implicits._
import org.zalando.grafter.{Start, StartResult}
import org.zalando.grafter.macros.{reader, readers}
import org.zalando.grafter.syntax.rewriter._
@readers
case class ApplicationConfig(httpConfig: HttpConfig)
@readers
case class HttpConfig(cfg1: HttpSubConfig1, cfg2: HttpSubConfig2)
case class HttpSubConfig1(port: Int)
case class HttpSubConfig2(host: String)
@reader
case class HttpClient(config: HttpSubConfig2) extends Start {
override def start: Eval[StartResult] = StartResult.eval("HttpClient")(println("Start HttpClient"))
}
@reader
case class SomeService(client: HttpClient) extends Start {
override def start: Eval[StartResult] = StartResult.eval("SomeService")(println("Start SomeService"))
}
@reader
case class Application(someService: SomeService)
object MyApp extends App {
val config = ApplicationConfig(HttpConfig(HttpSubConfig1(80), HttpSubConfig2("bla")))
val app = Application.reader[ApplicationConfig].apply(config).singletons
val started = app.startAll.value
if (started.forall(_.success))
println("application started successfully")
else
println(started.mkString("\n"))
}
could not find implicit value for parameter someServiceReader: cats.data.Reader[...ApplicationConfig,....SomeService]
HttpConfig
with @readers
and then import HttpConfig._
where you want to create the application. I’ll try to find a fix that’s working in all cases.