diff --git a/LaunchDarkly/LaunchDarkly/LDClient.swift b/LaunchDarkly/LaunchDarkly/LDClient.swift index 2c2e3c16..2c251917 100644 --- a/LaunchDarkly/LaunchDarkly/LDClient.swift +++ b/LaunchDarkly/LaunchDarkly/LDClient.swift @@ -681,7 +681,7 @@ public class LDClient { return } - let serviceFactory = serviceFactory ?? ClientServiceFactory(config: config) + let serviceFactory = serviceFactory ?? ClientServiceFactory(logger: config.logger) var keys = [config.mobileKey] keys.append(contentsOf: config.getSecondaryMobileKeys().values) serviceFactory.makeCacheConverter().convertCacheData(serviceFactory: serviceFactory, keysToConvert: keys, maxCachedContexts: config.maxCachedContexts) @@ -783,7 +783,7 @@ public class LDClient { private init(serviceFactory: ClientServiceCreating, configuration: LDConfig, startContext: LDContext?, completion: (() -> Void)? = nil) { self.serviceFactory = serviceFactory - environmentReporter = self.serviceFactory.makeEnvironmentReporter() + environmentReporter = self.serviceFactory.makeEnvironmentReporter(config: configuration) flagCache = self.serviceFactory.makeFeatureFlagCache(mobileKey: configuration.mobileKey, maxCachedContexts: configuration.maxCachedContexts) flagStore = self.serviceFactory.makeFlagStore() flagChangeNotifier = self.serviceFactory.makeFlagChangeNotifier() @@ -797,7 +797,7 @@ public class LDClient { context = AutoEnvContextModifier(environmentReporter: environmentReporter, logger: config.logger).modifyContext(context) } - service = self.serviceFactory.makeDarklyServiceProvider(context: context, envReporter: environmentReporter) + service = self.serviceFactory.makeDarklyServiceProvider(config: config, context: context, envReporter: environmentReporter) diagnosticReporter = self.serviceFactory.makeDiagnosticReporter(service: service, environmentReporter: environmentReporter) eventReporter = self.serviceFactory.makeEventReporter(service: service) connectionInformation = self.serviceFactory.makeConnectionInformation() diff --git a/LaunchDarkly/LaunchDarkly/ServiceObjects/ClientServiceFactory.swift b/LaunchDarkly/LaunchDarkly/ServiceObjects/ClientServiceFactory.swift index 428a0df4..a6c8dd97 100644 --- a/LaunchDarkly/LaunchDarkly/ServiceObjects/ClientServiceFactory.swift +++ b/LaunchDarkly/LaunchDarkly/ServiceObjects/ClientServiceFactory.swift @@ -1,11 +1,12 @@ import Foundation import LDSwiftEventSource +import OSLog protocol ClientServiceCreating { func makeKeyedValueCache(cacheKey: String?) -> KeyedValueCaching func makeFeatureFlagCache(mobileKey: String, maxCachedContexts: Int) -> FeatureFlagCaching func makeCacheConverter() -> CacheConverting - func makeDarklyServiceProvider(context: LDContext, envReporter: EnvironmentReporting) -> DarklyServiceProvider + func makeDarklyServiceProvider(config: LDConfig, context: LDContext, envReporter: EnvironmentReporting) -> DarklyServiceProvider func makeFlagSynchronizer(streamingMode: LDStreamingMode, pollingInterval: TimeInterval, useReport: Bool, service: DarklyServiceProvider) -> LDFlagSynchronizing func makeFlagSynchronizer(streamingMode: LDStreamingMode, pollingInterval: TimeInterval, @@ -16,7 +17,7 @@ protocol ClientServiceCreating { func makeEventReporter(service: DarklyServiceProvider) -> EventReporting func makeEventReporter(service: DarklyServiceProvider, onSyncComplete: EventSyncCompleteClosure?) -> EventReporting func makeStreamingProvider(url: URL, httpHeaders: [String: String], connectMethod: String, connectBody: Data?, handler: EventHandler, delegate: RequestHeaderTransform?, errorHandler: ConnectionErrorHandler?) -> DarklyStreamingProvider - func makeEnvironmentReporter() -> EnvironmentReporting + func makeEnvironmentReporter(config: LDConfig) -> EnvironmentReporting func makeThrottler(environmentReporter: EnvironmentReporting) -> Throttling func makeConnectionInformation() -> ConnectionInformation func makeDiagnosticCache(sdkKey: String) -> DiagnosticCaching @@ -25,10 +26,10 @@ protocol ClientServiceCreating { } final class ClientServiceFactory: ClientServiceCreating { - private let config: LDConfig + private let logger: OSLog - init(config: LDConfig) { - self.config = config + init(logger: OSLog) { + self.logger = logger } func makeKeyedValueCache(cacheKey: String?) -> KeyedValueCaching { @@ -43,7 +44,7 @@ final class ClientServiceFactory: ClientServiceCreating { CacheConverter() } - func makeDarklyServiceProvider(context: LDContext, envReporter: EnvironmentReporting) -> DarklyServiceProvider { + func makeDarklyServiceProvider(config: LDConfig, context: LDContext, envReporter: EnvironmentReporting) -> DarklyServiceProvider { DarklyService(config: config, context: context, envReporter: envReporter, serviceFactory: self) } @@ -60,7 +61,7 @@ final class ClientServiceFactory: ClientServiceCreating { } func makeFlagChangeNotifier() -> FlagChangeNotifying { - FlagChangeNotifier(logger: config.logger) + FlagChangeNotifier(logger: logger) } func makeEventReporter(service: DarklyServiceProvider) -> EventReporting { @@ -91,7 +92,7 @@ final class ClientServiceFactory: ClientServiceCreating { return EventSource(config: config) } - func makeEnvironmentReporter() -> EnvironmentReporting { + func makeEnvironmentReporter(config: LDConfig) -> EnvironmentReporting { let builder = EnvironmentReporterBuilder() if let info = config.applicationInfo { @@ -106,7 +107,7 @@ final class ClientServiceFactory: ClientServiceCreating { } func makeThrottler(environmentReporter: EnvironmentReporting) -> Throttling { - Throttler(logger: config.logger) + Throttler(logger: logger) } func makeConnectionInformation() -> ConnectionInformation { @@ -122,6 +123,6 @@ final class ClientServiceFactory: ClientServiceCreating { } func makeFlagStore() -> FlagMaintaining { - FlagStore(logger: config.logger) + FlagStore(logger: logger) } } diff --git a/LaunchDarkly/LaunchDarklyTests/Mocks/ClientServiceMockFactory.swift b/LaunchDarkly/LaunchDarklyTests/Mocks/ClientServiceMockFactory.swift index c24f689f..47cc5f05 100644 --- a/LaunchDarkly/LaunchDarklyTests/Mocks/ClientServiceMockFactory.swift +++ b/LaunchDarkly/LaunchDarklyTests/Mocks/ClientServiceMockFactory.swift @@ -34,7 +34,7 @@ final class ClientServiceMockFactory: ClientServiceCreating { return makeCacheConverterReturnValue } - func makeDarklyServiceProvider(context: LDContext, envReporter: EnvironmentReporting) -> DarklyServiceProvider { + func makeDarklyServiceProvider(config: LDConfig, context: LDContext, envReporter: EnvironmentReporting) -> DarklyServiceProvider { DarklyServiceMock(config: config, context: context) } @@ -111,7 +111,7 @@ final class ClientServiceMockFactory: ClientServiceCreating { } var makeEnvironmentReporterReturnValue: EnvironmentReportingMock = EnvironmentReportingMock() - func makeEnvironmentReporter() -> EnvironmentReporting { + func makeEnvironmentReporter(config: LDConfig) -> EnvironmentReporting { return makeEnvironmentReporterReturnValue }