Skip to content

Multiple versions of live dependency #88

Answered by mbrandonw
Namedix asked this question in Q&A
Discussion options

You must be logged in to vote

It sounds like you want multiple versions of APIClient available in your application at once? If so, then you are free to add as many computed properties to DependencyValues as you want. You just need to create a separate type to act as a key:

private enum AuthorizedAPIClientKey: DependencyKey { /* ... */ }
extension DependencyValues {
  var authorizedApiClient: ApiClient {
    get { self[AuthorizedAPIClientKey.self] }
    set { self[AuthorizedAPIClientKey.self] = newValue }
  }
}

private enum NonAuthorizedAPIClientKey: DependencyKey { /* ... */ }
extension DependencyValues {
  var nonAuthorizedApiClient: ApiClient {
    get { self[NonAuthorizedAPIClientKey.self] }
    set { self[NonAuth…

Replies: 1 comment 9 replies

Comment options

You must be logged in to vote
9 replies
@mbrandonw
Comment options

@Muhammed9991
Comment options

@stephencelis
Comment options

@mbrandonw
Comment options

@Muhammed9991
Comment options

Answer selected by Namedix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants