diff --git a/Sources/FactoryKit/FactoryKit/Modifiers.swift b/Sources/FactoryKit/FactoryKit/Modifiers.swift index ac4ec3a3..8097ee6d 100644 --- a/Sources/FactoryKit/FactoryKit/Modifiers.swift +++ b/Sources/FactoryKit/FactoryKit/Modifiers.swift @@ -175,9 +175,7 @@ extension FactoryModifying { case .arg, .args, .device, .simulator: registration.context(context, key: registration.key, factory: factory) default: - #if DEBUG registration.context(context, key: registration.key, factory: factory) - #endif break } } diff --git a/Sources/FactoryKit/FactoryKit/Registrations.swift b/Sources/FactoryKit/FactoryKit/Registrations.swift index 06f5027b..33b16f15 100644 --- a/Sources/FactoryKit/FactoryKit/Registrations.swift +++ b/Sources/FactoryKit/FactoryKit/Registrations.swift @@ -86,11 +86,21 @@ public struct FactoryRegistration: Sendable { traceNewType = "O" // .onTest, .onDebug, etc. #endif current = found.factory + } else if let found = options?.factoryForCurrentContext()?.untypedFactory as? @Sendable (P) -> T { + #if DEBUG + traceNewType = "O" // .onTest, .onDebug, etc. (cross-module) + #endif + current = found } else if let found = manager.registrations[key] as? TypedFactory { #if DEBUG traceNewType = "R" // .register {} #endif current = found.factory + } else if let found = manager.registrations[key]?.untypedFactory as? @Sendable (P) -> T { + #if DEBUG + traceNewType = "R" // .register {} (cross-module) + #endif + current = found } else { #if DEBUG traceNewType = "F" // Factory { ... } @@ -341,14 +351,12 @@ extension FactoryOptions { } } if let contexts = contexts, !contexts.isEmpty { - #if DEBUG if FactoryContext.current.isPreview, let found = contexts["preview"] { return found } if FactoryContext.current.isTest, let found = contexts["test"] { return found } - #endif if FactoryContext.current.isSimulator, let found = contexts["simulator"] { return found } @@ -378,8 +386,11 @@ internal struct FactoryDebugInformation { #endif // Internal Factory type -internal protocol AnyFactory {} +internal protocol AnyFactory { + var untypedFactory: Any { get } +} internal struct TypedFactory: AnyFactory { let factory: @Sendable (P) -> T + var untypedFactory: Any { factory } } diff --git a/Sources/FactoryKit/FactoryKit/Resolver.swift b/Sources/FactoryKit/FactoryKit/Resolver.swift index 7fda0774..c2fb07d4 100644 --- a/Sources/FactoryKit/FactoryKit/Resolver.swift +++ b/Sources/FactoryKit/FactoryKit/Resolver.swift @@ -69,6 +69,8 @@ extension Resolving { let key = FactoryKey(type: T.self, key: globalResolverKey) if let factory = manager.registrations[key] as? TypedFactory { return Factory(FactoryRegistration(key: globalResolverKey, container: self, factory: factory.factory)) + } else if let factory = manager.registrations[key]?.untypedFactory as? @Sendable (Void) -> T { + return Factory(FactoryRegistration(key: globalResolverKey, container: self, factory: factory)) } // otherwise return nil return nil