Prism use of discovered service

50 Views Asked by At

Suppose a Prism version 8 WPF module has a ViewModel which needs to call on a service. the service implements IService, but there exists a number of implementations of this service. Each implementation is a file (class library), possibly as a IModule (see below).

The user shall be able to configure which file to use either by configuration or by a folder's content.

Obviously(?) I am thus thinking of Module discovery by creating the right type of ModuleCatalog while "bootstrapping" the application and the service could thus be contained in this module. If the call is a void call ("fire-and-forget") I guess I could simply use EventAggregator (implementing the service as an observer), however the call returns a value.

What is the best approach solving this? (I would like to avoid writing my own assembly "discovering/loading" of some kind of a swappable service implementation dll file)

1

There are 1 best solutions below

5
Haukinger On BEST ANSWER

If you can inject IEventAggregator, you can inject IService, can't you?

If no module registered an implementation, you'll get an exception. If more than one module did, the last one wins (with unity as container, at least).