Skip to content

Commit b477bd8

Browse files
authored
Update 2024_12_30_dependency_injection_tf.md
cosmetics
1 parent 49e7927 commit b477bd8

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

2024_12_30_dependency_injection_tf.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Prerequisite: the reader is familiar with the previous part: https://github.com
88

99
Ok. Let’s adjust our type-based injection framework to the effect systems. This text is a result of joint work with Ivan Kyrylov during GSoC-2024. The main work was not about dependency injection but abstract representations of effect. Static dependency injection was a starting point for Ivan's journey. Our first attempt was based on another approach than here (we tried to automatically assemble a type map of needed injections, which, as a state of scala-3.x, is impossible because we can’t return context function from macros), but during this stage, we receive some understanding, what should work.
1010

11-
At first, what make dependency injection different in the effect system environment?
11+
First, what makes dependency injection different in the effect system environment?
1212
- Types of dependencies are encoded into the type of enclosing monad.
1313
- Retrieving of dependencies can be asynchronous:
1414

@@ -102,7 +102,7 @@ trait ConnectionPool {
102102
```
103103
(assuming minimal [ToyMonad](https://github.com/rssh/scala-appcontext/blob/59014c7aecacf81ea3fb6f9415ed603001032248/tagless-final/shared/src/test/scala/com/github/rssh/toymonad/ToyMonad.scala#L15) )
104104

105-
Here, new subscriber bounds will trigger search for `UserDatabase`(1) which will trigger search for `ConnectionPool`(3) which at first will be searched in the `InAppContext[..][F]` scope which will trigger building of `AppContextProviders[ConnectionPool*:EmptyTuple]`(4) which will be called because `InAppContext[(ConnectionPool *: EmptyTuple])` is a type parameter of enclosing function and then will start searching in enclosing scope (5).
105+
Here, new subscriber bounds will trigger search for `UserDatabase`(1) which will trigger a search for `ConnectionPool`(3) which at first will be searched in the `InAppContext[..][F]` scope which will trigger the building of `AppContextProviders[ConnectionPool*:EmptyTuple]`(4) which will be called because `InAppContext[(ConnectionPool *: EmptyTuple])` is a type parameter of enclosing function and then will start searching in enclosing scope (5).
106106

107107
The problem is that if step (4) triggers our macro and the macro produces an error, we will report an error, not be able to continue a search, and never reach step (5).
108108

@@ -158,17 +158,17 @@ See [Example 5](https://github.com/rssh/scala-appcontext/blob/main/tagless-final
158158

159159
## Concrete monad style
160160

161-
Yet one popular style is using a concrete monads, for example `IO` instead `F[_]`. In such case we don’t need `InAppContext` and can pass providers as in core case, as context parameters. What providers to use: `AppContextProvider or AppContextAsyncProviders` become a question of taste. You even can use `AppContextProviderModule` with async dependencies.
161+
Yet one popular style is using a concrete monads, for example `IO` instead `F[_]`. In such case, we don’t need `InAppContext` and can pass providers, as in the core case, as context parameters. What providers to use: `AppContextProvider or AppContextAsyncProviders` becomes a question of taste. You can even use `AppContextProviderModule` with async dependencies.
162162

163163
[Example](https://github.com/rssh/scala-appcontext/blob/main/tagless-final/jvm/src/test/scala/com/github/rssh/appcontexttest/Example7Test.scala)
164164

165165
## Environment effects.
166166

167-
If we open the theme of using type-driven dependency injection in the effect systems, maybe we should say a few words about libraries like zio or kyo, which provide their implementation of dependency injection.
168-
All of them are based on the concept that types needed for computation are encoded in their signature (similar to our tagless-final approach). In theory, our approach can simplify interaction points with such libraries (i.e., we can assemble the needed computation environment from providers).
167+
If we open the theme of using type-driven dependency injection in the effect systems, we should say a few words about libraries like zio or kyo, which provide their implementation of dependency injection.
168+
All of them are based on the concept that types needed for computation are encoded in their signature (similar to our tagless-final approach). Theoretically, our approach can simplify interaction points with such libraries (i.e., we can assemble the needed computation environment from providers).
169169

170170

171-
That’s all for today. The tagless final part are published as a subproject in `appcontext` with name “appcontext-tf”,
171+
That’s all for today. The tagless final part is published as a subproject in `appcontext` with name “appcontext-tf”,
172172
(github: https://github.com/rssh/scala-appcontext )
173173
You can try it using `“com.github.rssh” %%% “appcontext-tf” % “0.2.0”` as dependency. (maybe it should be joined with the core ?) I will be grateful for problem reports and suggestions for better names.
174174

0 commit comments

Comments
 (0)