Reputation: 3733
I find the lambda expressions needed for importing of properties somewhat confusing and I am trying to also understand how to use MEF conventions for importing and exporting so maybe I am trying to take on too much at once.
I am exporting ResourceDictionary
with a contract name which I imported previously like this:
[ImportMany("ApplicationResources", typeof(ResourceDictionary))]
public IEnumerable<ResourceDictionary> Views { get; set; }
Which works well and is fine, however I am now trying to import this via a RegistrationBuilder
but not fully understanding how to do this.
This exports them I believe (but I have to be honest I don't fully understand the syntax):
var registration = new RegistrationBuilder();
registration.ForTypesDerivedFrom<ResourceDictionary>()
.Export<ResourceDictionary>(x => x.AsContractName("ApplicationResources"));
I have a property in my App
that I wish to populate
So tried this (carried out within the App itself)
registration.ForType<App>()
.ImportProperty<ResourceDictionary>(x => x.Views);
But this isn't working and I am guessing I need to set contract name somehow? Can anyone tell me what the syntax for this is? Maybe if I can see the correc syntax I can better understand how it works... I hope!
Upvotes: 0
Views: 1135
Reputation: 3733
Typically it turns out that I found the solution after posting the question. I don't tend to answer my own questions but as it had me stuch for a while and in case it helps anyone else this is what works:
registration.ForType<App>()
.ImportProperty<ResourceDictionary>(x => x.Views, ib => ib.AsContractName("ApplicationResources"));
However this only works if I use SafisfyImportsOnce
rather than ComposeParts
which I am slightly confused about
Upvotes: 1