MEF instance management
- by Lawrence A. Contreras
I am working on application that has multiple modules and sub modules. Here's what I need to do:
ModuleA has a sub module SubModuleA, SubModuleB, SubModuleC.
I want to export ModuleA, SubModuleA, SubModuleB, SubModuleC.
ModuleA can have multiple instances.
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.