Ref #273 Need help for `Effect Type`'s Injection
@adamw Can't reopen https://github.com/softwaremill/macwire/issues/273 and create a new issue since reproduct the problem.
I use macwire to implement a web-app's injection using cats-effect with a simple way.
And it seems that it works in any effect type.
But some code not works well.
Code Link
Line 20 and Line 21 can not use macwire since "injection by name" is the same as "injection by varible name" in this injection style. Hoping for help to make these code more friendly.
sbt command
sbt>wire-web-scala/reStart
and input the url in browser.
http://127.0.0.1:8080/api/cats
or
http://127.0.0.1:8080/api/{StringParameter}
Can you create a minimised example, which would show the problem?
@adamw Already reproducted. Have a look if there are any other needs. Repo djx314/macwire-issue281 Injection code that need macwire Point Line All code
Run result
sbt:macwire-issue281> run
[info] running macwire.test.app.MainApp
resourceA value:5
resourceB value:2
macwire-issue281 executed successful.
[success] Total time: 1 s, completed 2023-3-17 3:41:23
Provide a quick fix and expect a more reasonable approach. Code link
class AppInjection {
lazy val namedInstance: Named = Named("macwire-issue281")
private case class ServiceBImpl(test: PrintString) {
def build(resourceB: DBResource): ServiceB = ServiceB(resourceB = resourceB, test = test)
}
def serviceCResource[F[_]]: Resource[F, ServiceC] = wire[DBResourceA].resource.flatMap(dbA =>
wire[DBResourceB].resource.flatMap(dbB =>
wire[PrintStringResource].resource.map { printlnString =>
lazy val serviceA: ServiceA = ServiceA(resourceA = dbA) // Injection by name.
lazy val serviceBImpl: ServiceBImpl = wire[ServiceBImpl]
lazy val serviceB: ServiceB = serviceBImpl.build(resourceB = dbB) // Injection by name and injection by type.
wire[ServiceC]
}
)
)
}