MEF instance management

Posted by Lawrence A. Contreras on Stack Overflow See other posts from Stack Overflow or by Lawrence A. Contreras
Published on 2013-06-24T07:37:35Z Indexed on 2013/06/26 10:21 UTC
Read the original article Hit count: 191

Filed under:
|
|
|

I am working on application that has multiple modules and sub modules. Here's what I need to do:

  1. ModuleA has a sub module SubModuleA, SubModuleB, SubModuleC.
  2. I want to export ModuleA, SubModuleA, SubModuleB, SubModuleC.
  3. ModuleA can have multiple instances.
  4. Whenever I import ModuleA inside the sub modules, I want to get the correct instance and also when I import SubModuleA,SubModuleB and SubModuleC inside other classes.

How can I manage that scenario using MEF? Do I really need to use MEF.

Updated: Here's a quick example:

public class School
{
    List<Classroom> classRooms { get; set; }
}

[Export]
public class Classroom
{
    List<Teacher> teachers { get; set; }
}

public class Teacher
{
    List<Student> students { get; set; }
}

public class Student
{
    [Import]
    Classroom classroom { get; set; }
}

As you can see, I want to export the classroom class because I need to import it in the Student class, let's just say that I really need the classroom class inside the student class. I want to skip the part where we pass the classroom to the teacher and from the teacher we'll pass it to the student. But when I import classroom, I want to have the correct instance where that class room contains the teacher of the student.

© Stack Overflow or respective owner

Related posts about c#

Related posts about wpf