Skip to content

Commit 2c3f863

Browse files
committed
Drop dependency injection section
It is now mostly confusing and does not convey a new point. There was a point once to it, in an earlier design where the two roles of an implicit parameters were separated. Then the example was much nicer. It was left in, to show that it's in principle still possible to do this even if the two parameter roles are not separated. But without that discussion it misses context.
1 parent a05717e commit 2c3f863

File tree

1 file changed

+0
-25
lines changed

1 file changed

+0
-25
lines changed

docs/docs/reference/witnesses/witness-params.md

-25
Original file line numberDiff line numberDiff line change
@@ -46,31 +46,6 @@ def g with (xy: (A, B))
4646
g with ((a, b))
4747
```
4848

49-
## Application: Dependency Injection
50-
51-
Witnesses can be used for dependency injection with constructor parameters. As an example, say we have four components `C1,...,C4` each of which depend on some subset of the other components. Constructor-based dependency injection defines these components as classes with explicitly passed parameters. E.g.,
52-
```scala
53-
class C1(c2: C2, c3: C3) { ... }
54-
class C2(c1: C1, c4: C4) { ... }
55-
class C3(c2: C3, c4: C4) { ... }
56-
class C4(c1: C1, c3: C3, c3: C3) { ... }
57-
```
58-
The components can then be "wired together" by defining a set of local witnesses:
59-
```scala
60-
{ witness c1 with (c1: C1, c2: C2, c3: C3) for C1(c1, c2, c3)
61-
witness c2 with (c1: C1, c4: C4) for C2 (c1, c4)
62-
witness c3 with (c2: C3, c4: C4) for C3(c2, c4)
63-
witness c4 with (c1: C1, c3: C3, c4: C4) for C4(c1, c3, c4)
64-
(c1, c2, c3, c4)
65-
}
66-
```
67-
Note that component dependencies in `C1, ..., C4` are _not_ defined themselves as implicit parameters. This prevents components from spreading into the implicit namespace of other components and keeps the wiring strictly to the interface of these modules.
68-
69-
This scheme is essentially what MacWire does. MacWire was implemented as a macro library. It requires whitebox macros which will no longer be supported in Scala 3.
70-
71-
I considered for a while an alternative design where the two notions of an implicit parameter (argument gets synthesized vs. parameter is itself available as an implicit value) are separated. This would allow a nicer expression of component assembly which would not require that dependencies are repeated in the witnesses. The most significant downside of the alternative design is that it's likely to induce choice fatigue. In most cases, implicit parameters should be available itself as a witness, so asking for an opt-in each time a parameter is defined
72-
became quickly tiresome.
73-
7449
## Implicit Function Types and Closures
7550

7651
Implicit function types are expressed using the new reserved operator `|=>`. Examples:

0 commit comments

Comments
 (0)