sentry-cocoa
sentry-cocoa copied to clipboard
Refactor integration entry points in Swift
Description
At this point every integration has an Objective-C entrypoint, e.g. SentryCrashIntegration.m or SentryANRTrackingIntegration.m. They are initialized from the - SentrySDKInternal#installIntegrations using dynamic calling of the initializer (without parameters).
We should rewrite the integrations in Swift, using constructor-based dependency injection to remove the usage of + SentryDependencyContaine#shareInstance.
Potential approach could be introducing factories for each integration, accepting the entire dependency container as the input, allowing us to keep using a generic SentryIntegrationProtocol with an install method.
I'd suggest something roughly like this:
protocol SentryIntegration {
typealias DependencyProvider
func start(with options: Options)
}
protocol ProcessInfoProviding {
var processInfo: ProcessInfo { get }
}
final class MyIntegration<DependencyProvider: ProcessInfoProviding> {
func start(with options: Options) {
let processInfo = DependencyProvider.processInfo
}
}
final class SentryDependencyContainer: ProcessInfoProviding {
...
}
MyIntegration<SentryDependencyContainer>.start(with: options)