softwaremill / softwaremill/macwire

Support parameters in wire[] to override dependencies

Open
#7 6 comments 1 reaction 0 assignees View on GitHub

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.