Introduction
The SessionModel class is a service locator that provides several services (I will develop my system architecture in the future, but now I need to do it that way).
Code
I edited the following part of the code as Short, Self Contained, Correct (Compilable), Example (SSCCE):
using System; using System.ComponentModel.Composition; using System.ComponentModel.Composition.Hosting; namespace ConsoleApplication1 { internal class Program { private static void Main(string[] args) { var sessionModel = new SessionModel(3);
Problem
I would like the MEF to consider the details (i.e. SomeService ) exported by the service locator when linking the other parts, but unfortunately this does not work.
First case
When I try to get the exported value for ISomeService , there is a System.ComponentModel.Composition.ImportCardinalityMismatchException saying that there is no export with this contract name and identifier of the required type ( ConsoleApplication1.ISomeService ).
Second case
If I create a CompositionContainer using TypeCatalog , the exception is a little different. This System.ComponentModel.Composition.CompositionException tells me that MEF does not find a way to create ConsoleApplication1.SessionModel (this is correct and the reason I do it myself).
Additional Information
mefx says for both cases:
[Part] ConsoleApplication1.SessionModel from: DirectoryCatalog (Path=".") [Export] ConsoleApplication1.SessionModel.SomeService (ContractName="ConsoleApplication1.ISomeService") [Part] ConsoleApplication1.SessionModel from: AssemblyCatalog (Assembly="ConsoleApplication1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null") [Export] ConsoleApplication1.SessionModel.SomeService (ContractName="ConsoleApplication1.ISomeService")
What should I do? Is this possible using MEF or do I need to use Unity or StructureMap or something else? Can this be done with ExportProvider ?
source share