I am currently playing around with and reading up on Prism. I know that the suggested way is to have some common “services” that are defined as interfaces in the Infrastructure assembly that all modules can reference. Different modules can implement these interfaces and essentially register to provide these services. And other modules can “consume” these services.
I am wondering what happens if two different modules implement the interface and essentially provide the same service. Which service is a consumer going to get when calling the service interface.
Assume I have an INewsFeed and the BlogScraper module implements this service as well as the PrintMagazineScanner module. If I have another module that consumes this service, lets say by displaying the newsfeeds, which of these services is it going to get?
It depends on the IoC container that you use. Generally, if you try to register a service using the same interface twice, it will either throw an exception right away or will let you do so overriding the previous registration or it will throw an exception when you try to request a single instance while there is more than one registered.
For example, if you take MEF, you can export multiple services using the same contract (interface), but when you import those services you have to define a collection property with the
ImportManyattribute on it: