Best practices for handling multiple dependencies that conform to the same protocol? #268
BrentMifsud
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Here's an example:
In our app, we have a protocol called
KeyValueStore
UserDefaults conforms to it, and is the default implementation in most cases throughout our app.
But we do have some other implementations of it. For example, we have an implementation that is scoped to the user's currently active account. So if the user switches accounts, they aren't seeing values from their other account.
I see two potential options:
Option 1: multiple dependency keys
you could make a
UserDefaultsKeyValueStoreDependencyKey
and also aAccountScopedKeyValueStoreDependencyKey
Option 2: single dependency key, but replace via withDependencies
you would make a single
KeyValueStoreDependencyKey
and then when you need the account scoped value store, you would do:
Wondering what people's thoughts on a best practice for this? Especially since I essentially want these both to have a single instance throughout the code base.
Beta Was this translation helpful? Give feedback.
All reactions