Skip to content
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

Dependency Injection: Improve injection of main database #322

Merged
merged 3 commits into from
Oct 11, 2023

Conversation

phil1995
Copy link
Collaborator

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.

@tobihagemann tobihagemann added this to the 2.5.0 milestone Oct 11, 2023
@tobihagemann tobihagemann merged commit 264515a into develop Oct 11, 2023
2 checks passed
@tobihagemann tobihagemann deleted the dependency_injection_1 branch October 11, 2023 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants