Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I thought it would be possible to write the following code:

C#
[Export]
public class ClassA
{
}

public class ClassB
{
  private readonly Func<ClassA> classAProvider;

  [ImportingConstructor]
  public ClassB(Func<ClassA> classAProvider)
  {
    this.classAProvider = classAProvider;
  }

  public ClassA CreateClassA()
  {
    return classAProvider();
  }
}


Can you please help me figure out how I can inject a provider for ClassA into ClassB? I have noticed ExportFactory, but I don't like the fact that I have to dispose it.
Posted

1 solution

 
Share this answer
 
Comments
FantasticFiasco 9-Dec-12 6:45am    
Sorry, but none of the samples provided solves my problem. It's just basic MEF tutorials that has no relevance to my problem.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900