Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ref #273 Need help for Effect Type's Injection #281

Open
djx314 opened this issue Mar 15, 2023 · 5 comments
Open

Ref #273 Need help for Effect Type's Injection #281

djx314 opened this issue Mar 15, 2023 · 5 comments

Comments

@djx314
Copy link

djx314 commented Mar 15, 2023

@adamw Can't reopen #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.

@djx314 djx314 changed the title Ref #273 Need help for Effect Type Injection Ref #273 Need help for Effect Type's Injection Mar 15, 2023
@djx314
Copy link
Author

djx314 commented Mar 15, 2023

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}

@adamw
Copy link
Member

adamw commented Mar 16, 2023

Can you create a minimised example, which would show the problem?

@djx314
Copy link
Author

djx314 commented Mar 16, 2023

@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

@djx314
Copy link
Author

djx314 commented Mar 16, 2023

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

@djx314
Copy link
Author

djx314 commented Mar 17, 2023

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]
      }
    )
  )
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants