Dependency Injection: Improve injection of main database #322
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
Currently we inject most of the dependencies via the initializer relying by using a singleton as the default / live value.
This pollutes the initializers as we sometimes have a lot of small components abstracted away via protocols as dependencies.
Even worse we sometimes need to first initialize the value and then set it on app / extension launch. This is cumbersome and also lead to crashes in the past… although they were pretty easy to detect as you "just" need to run every target at least once.
Description
First proposal on how we could Improve the injection of dependencies by using the simple-swift-dependencies library.
In this PR I migrated the shared main database away from a pure singleton (which even got set manually on app / extension launch) implementation to a more controlled dependency with a default test value (a migrated in-memory database).
The library mentioned above does also fail the unit test if there is no test value provided and the dependency has not been mocked or it was not explicitly stated in the test case to use the live value.
If we decide to use this approach we can migrate all other database managers which use the main database easily.
Furthermore, we can eventually migrate at least every injected dependency which has a singleton as a default value to the proposed solution.