MEF : How can I import a class which has a constructor marked with the ImportingConstructorFlag?

The point is that if you use a contract (in your case "BirthdayJob") in your export, you need to specify that in your import as well. Like so.

The point is that if you use a contract (in your case "BirthdayJob") in your export, you need to specify that in your import as well. Like so: Export("BirthdayJob",typeof(ITest)) public partial class BirthdayTest : ITest { // class definition } And your import: public class MainClass { ImportMany("BirthdayJob",typeof(ITest)) private List Tests { get; set; } // class definition } The great thing about contracts is that they allow you to group instances of certain objects of a specific type and filter out any unwanted instances of objects of a specific type. MEF is the coolest!

Export("PeopleLivingInEdmontonAlbertaCanada",typeof(IPerson)) public Person KevinParkinson { get; set; }.

I've found the solution. In the export class of the foo class should be a reference of the derived interface. The constructor which have the importingconstructor flag should have also a reference to the interface.

Export public class Bar { ImportingConstructor public Bar(Import("Foo", typeof(IFoo))IFoo foo) //public Bar(Import(typeof(IFoo))IFoo foo) { this. Foo = foo; } public IFoo Foo { get; set;} } Export("Foo", typeof(IFoo)) public class Foo : IFoo { public Foo() { Message = ":-)"; } public string Message { get; set; } }.

Taking a wild guess, it is possibly the working directory of your DirectoryCatalog (depending on how you run the app. ) To verify that this is the problem, replace: DirectoryCatalog catalog = new DirectoryCatalog(@". /"); With either: DirectoryCatalog catalog = new DirectoryCatalog(@""); or: AssemblyCatalog catalog = new AssemblyCatalog(typeof(BirthdayTest).

Assembly).

Thank you for your answer, but the current directory (@". /") is right. I've verified that with the debugger.

After the ComposeParts() call,all assemblies are correct loaded and all parts are corrected listed... – pro Sep 7 '10 at 6:19 You're welcome - I'm out of ideas though. If you can post a complete (compilable) example I can take a look. – Nicholas Blumhardt Sep 11 '10 at 9:34.

In the code you posted, you are not, and this is why the Birthday test isn't being picked up.

Yes he is! Scroll down the code all the way - the class BirthdayJobParameter clearly exports IParameter – marc_s Sep 6 '10 at 16:45 @marc_s Oops, I must have missed the scroll bar! :) – Daniel Plaisted Sep 7 '10 at 2:58.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions