Equivalent of Resolver implement for multiple protocol
hyazel opened this issue · comments
Hyazel commented
Hello,
I'm currently migrating my code base from Resolver
to Factory
.
I have some registrations that use the same instance for multiple protocols like this :
main.register { XYZCombinedService() }
.implements(XYZFetching.self)
.implements(XYZUpdating.self)
What would be the equivalent for Factory
?
Thanks a lot !
Michael Long commented
Since they work differently, there's not a direct equivalent. Just make two factories.
var xyzFetching: Factory<XYZFetching> { self { XYZCombinedService() } }
var xyzUpdating: Factory<XYZUpdating> { self { XYZCombinedService() } }
Or, if you prefer
var xyzFetching: Factory<XYZFetching> { self { self.xyzCombined() } }
var xyzUpdating: Factory<XYZUpdating> { self { self.xyzCombined() } }
private var xyzCombined: Factory<XYZCombinedService> { self { XYZCombinedService() }.shared }
I'd use the later version if the combined service needs to be cached.
Hyazel commented
Ok thanks !