softwaremill / softwaremill/macwire
Support parameters in wire[] to override dependencies
Nobody has claimed this yet.
- Dominant language
- Scala
- Stars
- 1.3k
- Forks
- 77
- Avg merge
- 9m
- Merged PRs (30d)
- 4
Description
(One of the ideas from ScalaDays 2014 - by @matthewfarwell)
The wire[] method could accept parameters, which would be used to wire an instance of the given type; the parameters would take precedence over (override) vals/defs in wider scopes.
Example usage:
class Service(s2: Service2, s3: Service3, config: Map[String, String])
lazy val s2 = wire[Service2]
lazy val s3 = wire[Service3]
lazy val defaultConfig = Map("username" -> "default")
// here the given map would be used instead of the default
lazy val sA = wire[Service](Map("username" -> "admin"))
// here the default config map would be used and an alternative Service2 impl
lazy val sB = wire[Service](new Service2(...))
A parameter which doesn't match any of the constructor parameters of the wired type would result in a compile-time error.
This can be useful for:
- providing alternative implementations only for a single usage
- providing configuration values on a per-instance basis
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.
Research direction
Start by reviewing the wire[] API and the constructor-matching behavior described in the examples. Define how supplied parameters override wider-scope vals/defs, and verify that unmatched parameters produce a compile-time error while the shown Service examples resolve as intended.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- scala
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100