vapor / apns

Helpful extensions and abstractions for using APNSwift
MIT License
115 stars 30 forks source link

Feature Request: How to register the APNSClient with Application? #49

Closed idelfonsog2 closed 1 year ago

idelfonsog2 commented 1 year ago

Describe the bug

What's the best way to set the app.apns.client? I found myself using the repository pattern to try to inject a different APNS service implementation but I noticed the APNSwift comes with app.apns.client, which reminded me of how I previously implemented an aws integration that looked like this:

app.aws.client = AWSClient(httpClientProvider: .shared(app.http.client.shared))

I'm trying to achieve the same but app.apns.client is read only, can we documentation around it ?

Expected behavior

apns.apns.client = MyAPNSCustomClient....

in my AWS Application Extension I have the following:

public var client: AWSClient {
            get {
                guard let client = self.application.storage[ClientKey.self] else {
                    fatalError("AWSClient not setup. Use application.aws.client = ...")
                }
                return client
            }
            nonmutating set { self.application.storage.set(ClientKey.self, to: newValue) {
                    try $0.syncShutdown()
                }
            }
        }

Environment

Additional context

Add any other context about the problem here.

idelfonsog2 commented 1 year ago

Found implementation example in the testing suite. Adding documentation is the missing part

    app.apns.containers.use(
        apnsConfiguration,
        eventLoopGroupProvider: .createNew,
        responseDecoder: JSONDecoder(),
        requestEncoder: JSONEncoder(),
        backgroundActivityLogger: app.logger,
        as: .default)