You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 2024_12_30_dependency_injection_tf.md
+6-6Lines changed: 6 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@ Prerequisite: the reader is familiar with the previous part: https://github.com
8
8
9
9
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.
10
10
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?
12
12
- Types of dependencies are encoded into the type of enclosing monad.
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 typeparameter 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 typeparameter of enclosing function and then will start searching in enclosing scope (5).
106
106
107
107
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).
108
108
@@ -158,17 +158,17 @@ See [Example 5](https://github.com/rssh/scala-appcontext/blob/main/tagless-final
158
158
159
159
##Concrete monad style
160
160
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 asin core case, ascontext parameters. What providers to use: `AppContextProvider or AppContextAsyncProviders` become a question of taste. Youeven 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,asinthe core case, ascontext parameters. What providers to use: `AppContextProvider or AppContextAsyncProviders` becomes a question of taste. You can even use `AppContextProviderModule` with async dependencies.
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).
169
169
170
170
171
-
That’s all for today. The tagless final part are published asa subproject in `appcontext` with name “appcontext-tf”,
171
+
That’s all for today. The tagless final part is published asa subproject in `appcontext` with name “appcontext-tf”,
You can try it using `“com.github.rssh” %%% “appcontext-tf” % “0.2.0”` asdependency. (maybe it should be joined with the core ?) I will be grateful for problem reports and suggestions for better names.
0 commit comments