Export with Import

Sep 23, 2009 at 7:21 AM

Hello,

Somehow I miss some point.

I try to do this:

A application (HOST) imports some Assemblies in a directory.
A Assemblies (Provider) needs some infos from the HOST.
So the HOST export the Interface ILastIndexValueEntries and the Provider imports it.

HOST


[Export(typeof(ILastIndexValueEntries))]
    class Host:ILastIndexValueEntries
    {

        [ImportMany(typeof(IProvider))]
        public Lazy<IProvider, IDictionary<string,object>>[] providers { get; private set; }

Assembly IProvider
[Export(typeof(IProvider))]
    class DefaultProvider:IProvider
    {
        [Import(typeof(ILastIndexValueEntries))]
        private Lazy<ILastIndexValueEntries> dataSource { get; set; }

Problem
With the constelation above i didn't find a provider:

            ....container.ComposeParts(this);
            //providers.Count() == 0

If i remove [Import(typeof(ILastIndexValueEntries))] in Assembly IProvider providers.Count()==1

What's wrong? Where is the bug?
Can someone help me?
Thanx

Sep 23, 2009 at 8:34 AM

Found it...
I have to do this

var catalog = new AggregateCatalog(new ComposablePartCatalog[] {
                      new AssemblyCatalog(System.Reflection.Assembly.GetExecutingAssembly()),
                      new DirectoryCatalog(providerpath) });

Thanks to me;-)