Module scoped services #2392
-
Is it possible to register service using the same interface, but different implementations for a specific module? So the implementation must be resolved only in that module where it is registered. Lets look at example: each specific module has its own translation resources, so I want to have a TranslationService to handle those resources, but only for the current module. So, lets assume I have two modules registered in my application [Module 1] and [Module 2]. I have somewhere a shared assembly where ITranslationService interface is located. [Module 1] has its own implementation of ITranslationService and [Module 2] also has its own implementation of ITranslationService. So is that a problem? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
No, Prism does not support resolving modules using a scoped service. You would need to customize Prism to do this. however, this would be no simple task. Plus, scoped services wouldn't really help you here anyways since your main problem is you have multiple implementations for a single interface. Usually translation services are not specific to modules. There is usually one translation service that works everywhere. In your scenario, one approach could be to create a "marker" interface. This would essentially be another interface like |
Beta Was this translation helpful? Give feedback.
No, Prism does not support resolving modules using a scoped service. You would need to customize Prism to do this. however, this would be no simple task. Plus, scoped services wouldn't really help you here anyways since your main problem is you have multiple implementations for a single interface.
Usually translation services are not specific to modules. There is usually one translation service that works everywhere. In your scenario, one approach could be to create a "marker" interface. This would essentially be another interface like
interface IModule1Service : ITranslationService
and then register that with the container in each module.