Macwire does not consider outer trait members to be candidates for wiring
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
Research direction
Start with the nested-trait example in the issue and the linked Play example at app/GreetingApplicationLoader.scala, then trace Macwire's wiring-resolution entry point for visible members. Done means the inner FooController wiring can use the outer fooService without the reported missing-value error, with the example behavior verified.
Written by the indexing model from the issue text.
Description
If I have a trait with an inner trait like this:
trait FooComponents {
lazy val fooService: FooService = wire[FooService]
trait FooRequestScopedComponents {
def request: RequestHeader
def fooController: FooController = wire[FooController]
}
}
Macwire (2.3.0) is unable to see the fooService in the outer scope and will report an error like FooComponents.scala:20: Cannot find a value of type: [services.FooService]. Writing the code manually works fine.
My motivation here is to try to create a set of "request components", which are instantiated per-request and can have a dependency on the request. I prefer not to use a traditional "request scope" that uses thread locals because that can be hard to manage across thread boundaries in async frameworks like Play, and it seems far less intuitive than normal dependency injection.
I have a basic example Play app showing the approach here: https://github.com/gmethvin/play-scala-macwire-di-example/blob/50f4771/app/GreetingApplicationLoader.scala. I'd like to be able to replace many of those manual constructor calls with wire calls though.
- Dominant language
- Scala
- Stars
- 1.3k
- Forks
- 77
- Avg merge
- 9m
- Merged PRs (30d)
- 4
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from softwaremill/macwire
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
softwaremill/macwire#412 · 3 comments ·
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
softwaremill/macwire#391 · 1 comment ·
-
Difficulty 5/5 Over a week Newbie friendliness 20/100
softwaremill/macwire#301 · 2 comments ·
-
Difficulty 5/5 Over a week Newbie friendliness 20/100
softwaremill/macwire#281 · 5 comments ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
softwaremill/macwire#278 · 3 comments ·
All issues in softwaremill/macwire
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
ergoplatform/ergodocs#614 ·
-
area:ci enhancement requires-triage
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
apache/datafusion-comet#6078 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
-
[VL] madvise(WILLNEED) call fails in MmapFileStream because of wrong calculation of fetching length Openbug triage
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
chipsalliance/rocket-chip#3831 ·