-
-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Question] Global start/bootstrap logic before all tests #1983
Comments
This is what we do in general. Alternatively you can make named copies of the graphs that you use in the startup task. Though that may be bothersome to do - you'll need to assign names to all the components AND to their dependencies - to prevent dependencies from being memoized: val constructorOfUserService = AnyConstructor[UserService]
val constructorOfSomeRepository = AnyConstructor[SomeRepository]
def makeAllDependenciesNamed[A](functoid: Functoid[A], name: Identifier): Functoid[A] = {
val newProvider = functoid.get.replaceKeys {
case DIKey.TypeKey(tpe, m) =>
DIKey.IdKey(paramTpe, name.id, m)(name.idContract)
case k => k
}
Functoid(newProvider)
}
val globalModule = new ModuleDef {
make[UserService].named("global").from(makeAllDependenciesNamed(constructorOfUserService, "global"))
make[SomeRepository].named("global").from(makeAllDependenciesNamed(constructorOfSomeRepository, "global"))
... make[SomeRepositoryDep].named("global").from(...) ...
} There could be a better solution for this in the future with private bindings |
Thank you for the details and provided snippet @neko-kai! |
Hi, Team!
First of all, thank you all for the awesome Scala FP DI Framework. We use it a lot.
Today, I have one question regarding the best way of implementing global bootstrap logic to be run before all tests.
Currently, we do it like this
The problem:
Although we have our
fixtureBootstrap
run once before all tests, we have a problem with theuserService
and its dependencies. The arguments offixtureBootstrap
and ALL nested dependencies (there could be quite a lot of them) of the components in the arguments are created only once and shared across all tests.This is undesirable sometimes.
We potentially can only inject
Transactor[Task]
intofixtureBootstrap
only and duplicate some logic from other components likeuserService
to "unblock it" and make it re-creatable on every test, but there may be another way of doing it.Please kindly advise how we can define a global bootstrap logic without pinning some portion of the instances in the DI graph.
Thank you.
The text was updated successfully, but these errors were encountered: