c# - Configure and expose a singleton to all modules in a MEF/PRISM application -
I have an application (only one test) which uses MEF and PISM.
It is quite easy to export some exports that correspond to specific interfaces and load them to the manufacturer of the module being loaded, but I am trying to do something different.
The application starts, when it imports an implementation of IControllerClient. The built-in example needs to be configured (for example by shell) after which each module should be used in the application.
I do not want any public property on Shell or some supportive class that exposes this example, as possibly a bad practice ... and I really do not like it.
Update: Returning the question given below
We have several interfaces defined in an existing framework, mango They are loaded in various applications using MEF.
I used to be able to load them into a glasses application, for example:
[ImportingConstructorAttribute ()] Public HelloWorldView (IDataTransportService dataTransportService, IMessageFactory messageFactory, IDataFactory dataFactory, IDataProcessor dataProcessor, IDataCollector dataCollector) {var Customer = New ControllerCl Ient (DataTransport Services, Message Factor, Data Processor Data Collector); }
In this case, the module creates a valid example of the ControllerClient class.
But instead of passing those interfaces to the creator, I want to make a module manufacturer like this:
[ImportingSource Editor ()] Public Hellevard client ) {This.client = client; }
Manufacturer for the IClient implementation (ControllerClient) [ImportingConstructorAttribute ()] So I expected depencencies to be injected automatically at this point ... but used this code That's, the producer can never be reached.
What I need is an example of an ICLIIT interface that is used by all modules in the application. (I think the shared MIF is the default for import).
What is the best way to do this? Why can not I take ICLient near a module constructor, and what if I want to present an example of a class if it does not have knowledge of the mag?
Then in an MEF / prism app, you define this frequency, which can be used by all modules? And this is often referred to as the service (but I could get guidance to highlight services with unity / prism).
I hope that I work better by explaining my problem this time.
Update 2: is shared for the default MEF import, I can import the IClient implementation in every module, but then why I am not dependent injecting It needs to be detected
Reading your updated description, it seems that you can not configure the class in its constructor or after the solution to its import, you need some additional reference information. If this is the case, then what you can do is manually configure the class in the shell and manually add the export using the container's composites method. This will make your 'configured' frequency one that will be used to resolve any [export] tags you have applied to the class. Of course, before you build anything through that container you have to do this, which depends on the example.
Comments
Post a Comment