When you want to use a dependency injection system like Factory with multiple modules you often run into a “Who’s on first” dilemma.
Let’s say that ModuleP specifies an abstractAccountLoading protocol.
// ModuleP
public protocol AccountLoading {
func load() -> [Account]
}
Moving on, we have an accounting module, ModuleA, that displays our accounts, but needs one of those loaders to load them.
Finally, we have one more module, let’s call this one ModuleB, that knows how to build loaders of any type that we need.
Note that ModuleA and ModuleB are independent. Neither one knows about the other one, but both have a direct dependency on ModuleP, our master of models and protocols.
This is a classic modular contractural pattern.