none
MEF problem RRS feed

  • Question

  • I have this situation. There is code snippet:

    interface ICorePlugin
    {
    	void Initialize();
    }
    
    interface IAutomaticPlugin
    {
    	void InitializeAutomatic();
    }
    
    [Export(ICorePlugin)]
    class A:ICorePlugin
    
    {
    	...importmany automatic plugins...
    	
    	ctor
    	{
    		Loader.LoadPlugins(this, typeof(IAutomaticPlugin));
    	}
    	
    	public Initialize()
    	{
    		foreach(autoplugin in plugins)
    		{
    			autoplugin.InitializeAutomatic();
    		}
    	}	
    }
    
    [Export(IAutomaticPlugin)]
    class B:IAutomaticPlugin
    {	
    	ctor
    	{		
    	}
    	
    	public InitializeAutomatic()...
    }
    
    class Loader
    {
    	public static LoadPlugins(object pluginHost, Type pluginInterface)...
    }
    
    
    class Manager
    {
    	importmany ICorePlugin...
    	
    	ctor Manager
    	{
    		LoadPlugin(this, typeof(ICorePlugin));
    	}
    	
    	public void Start()
    	{
    		foreach(coreplugin in plugins)
    		{
    			coreplugin.Initialize();
    		}
    	}
    }

    In Loader class, LoadPlugins method surf throug directory and find right assembly, then add it to aggregate catalog and at the end ComposeParts from CompositionContainer. I check through debuger and I found all assembly that meet condition. When call start method for core plugin there is no action plugin in it, InitializeAutomatic is never called, there is no action plugin loaded into core plugin. I check directory everything is ok.

    What I doing wrong?


    • Moved by Lisa Zhu Monday, February 4, 2013 5:11 AM MEF related
    Thursday, January 31, 2013 5:57 PM

All replies

  • Hi,

    do you add the aggregate catalog to the composition container before you call Compose?

    Thursday, January 31, 2013 7:37 PM
  • Yes. Intrasting is that when I call Loader.LoadPlugins from ctor nothing happend. When I call Loader.LoadPlugins from Initialize methot from core plugin everything is ok... :O
    • Proposed as answer by chriga Monday, February 11, 2013 8:18 AM
    Thursday, January 31, 2013 7:42 PM
  • Hi nikolaradin,

    From your description, I ‘d like to move this post to  the most related forum.

    There are more  experts in this aspect, so you will get  better support and  may have more luck getting answers.

    Thanks for your understanding.

    Regards,


    Lisa Zhu [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, February 4, 2013 5:10 AM
  • So you have resolved your problem?
    Friday, February 8, 2013 12:30 PM