Skip to content
Discussion options

You must be logged in to vote

@havilog You can use @Dependency anywhere you need one, just be aware that cyclical dependencies are not supported (where A depends on B depends on A, etc.).

So in the above case, you could reach out to other dependencies directly in your static functions, or even a static computed property:

extension TokenClient: DependencyKey {
  static var liveValue: Self {
    // Expose a dependency to use later:
    @Dependency(\.network) var network

    return Self(
      token: {
        doSomeAdditionalFunction1()

        guard let credential = storage.load() else {
          return network.requestNewToken()
        }
            
        // ...
      }
    )
    
    private static func doSomeA…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@havilog
Comment options

@stephencelis
Comment options

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