@@ -16,38 +16,69 @@ public final class ServiceProviderInject<Container, Provider> {
1616 private var lazyInitToken : ServiceInjectReadyToken ?
1717 private var state = InjectState < Provider > ( )
1818
19+ // MARK: Common constructors
20+
1921 /// `keyPath` - key in container with value type `ServiceProvider`.
2022 public convenience init < Service> ( _ keyPath: KeyPath < Container , Provider > , file: StaticString = #file, line: UInt = #line)
2123 where Provider == ServiceProvider < Service > {
22- self . init ( baseInitFor: keyPath, file: file, line: line)
24+ self . init ( baseInitFor: keyPath, map : { $0 } , file: file, line: line)
2325 }
2426
2527 /// `keyPath` - key in container with optional value type `ServiceProvider?`.
2628 public convenience init < Service> ( _ keyPath: KeyPath < Container , Provider > , file: StaticString = #file, line: UInt = #line)
2729 where Provider == ServiceProvider < Service > ? {
28- self . init ( baseInitFor: keyPath, file: file, line: line)
30+ self . init ( baseInitFor: keyPath, map : { $0 } , file: file, line: line)
2931 }
3032
3133 /// `keyPath` - key in container with value type `ServiceParamsProvider`.
3234 public convenience init < Service, Params> ( _ keyPath: KeyPath < Container , Provider > , file: StaticString = #file, line: UInt = #line)
3335 where Provider == ServiceParamsProvider < Service , Params > {
34- self . init ( baseInitFor: keyPath, file: file, line: line)
36+ self . init ( baseInitFor: keyPath, map : { $0 } , file: file, line: line)
3537 }
3638
3739 /// `keyPath` - key in container with optional value type `ServiceParamsProvider?`.
3840 public convenience init < Service, Params> ( _ keyPath: KeyPath < Container , Provider > , file: StaticString = #file, line: UInt = #line)
3941 where Provider == ServiceParamsProvider < Service , Params > ? {
40- self . init ( baseInitFor: keyPath, file: file, line: line)
42+ self . init ( baseInitFor: keyPath, map: { $0 } , file: file, line: line)
43+ }
44+
45+ // MARK: ObjC constructors
46+
47+ /// `keyPath` - key in container with value type `ServiceProvider`, injected value type is `ServiceProviderObjC`.
48+ public convenience init < Service> ( objc keyPath: KeyPath < Container , ServiceProvider < Service > > , file: StaticString = #file, line: UInt = #line)
49+ where Provider == ServiceProviderObjC {
50+ self . init ( baseInitFor: keyPath, map: { ServiceProviderObjC ( $0) } , file: file, line: line)
51+ }
52+
53+ /// `keyPath` - key in container with optional value type `ServiceProvider?`, injected value type is `ServiceProviderObjC?`.
54+ public convenience init < Service> ( objc keyPath: KeyPath < Container , ServiceProvider < Service > ? > , file: StaticString = #file, line: UInt = #line)
55+ where Provider == ServiceProviderObjC ? {
56+ self . init ( baseInitFor: keyPath, map: { $0. map { ServiceProviderObjC ( $0) } } , file: file, line: line)
4157 }
4258
43- private init ( baseInitFor keyPath: KeyPath < Container , Provider > , file: StaticString , line: UInt ) {
59+ /// `keyPath` - key in container with value type `ServiceParamsProvider`, injected value type is `ServiceParamsProviderObjC`.
60+ public convenience init < Service, Params> ( objc keyPath: KeyPath < Container , ServiceParamsProvider < Service , Params > > , file: StaticString = #file, line: UInt = #line)
61+ where Provider == ServiceParamsProviderObjC {
62+ self . init ( baseInitFor: keyPath, map: { ServiceParamsProviderObjC ( $0) } , file: file, line: line)
63+ }
64+
65+ /// `keyPath` - key in container with optional value type `ServiceParamsProvider?`, injected value type is `ServiceParamsProviderObjC?`.
66+ public convenience init < Service, Params> ( objc keyPath: KeyPath < Container , ServiceParamsProvider < Service , Params > ? > , file: StaticString = #file, line: UInt = #line)
67+ where Provider == ServiceParamsProviderObjC ? {
68+ self . init ( baseInitFor: keyPath, map: { $0. map { ServiceParamsProviderObjC ( $0) } } , file: file, line: line)
69+ }
70+
71+
72+ // MARK: General
73+
74+ private init < SrcProvider> ( baseInitFor keyPath: KeyPath < Container , SrcProvider > , map: @escaping ( SrcProvider ) -> Provider , file: StaticString , line: UInt ) {
4475 setup { [ unowned self] container in
4576 guard let container = container else {
4677 fatalError ( " Not found Container for Inject " , file: file, line: line)
4778 }
4879
4980 let provider = container [ keyPath: keyPath]
50- self . state. storage. setEntity ( provider)
81+ self . state. storage. setEntity ( map ( provider) )
5182 }
5283 }
5384
0 commit comments