Open utybo opened 1 year ago
Idea for the step 3 of this whole plan, I think it would be better if we use the following behavior.
In cases where we could have a fundef:
@Fundef
annotation is present, register as a fundef,tegralDi {}
block, some function defineAsFundefIf { ... }
that takes the incoming function and, if it returns true true, will register it as a fundef as if a @Fundef
annotation was present. Multiple defineAsFundefIf
can be added and, if any of them evaluates to true
, the function will be registered as a fundefInjectionScope
)
The idea is to be able to define DI components as functions. This would unlock more advanced use cases, an obvious one being easier definition of simple web controllers and Ktor modules.
Usage
Here's an example of what this could look like.
Tegral Web Controllers
For example:
Tegral DI
Pros, cons and remarks
Pros
Indentiation
Saves an indentation space for controllers and modules and significantly simplifies their definition.
Ktor modules
Misc.
scope.optional()
) can easily be supported by using default parameters! (probably with nullable support, soA? = null
in a parameter would be the same asenv.getOrNull<A>()
)Cons
Qualifiers
put
syntax, becomes constructors are considered functions when using reflection. Either<KFunction object>.javaConstructor != null
.Remarks
init
block.Todo list
putFundef
putFundef
intoput
Drop annotation requirementsee below