Multiple Interfaces

Dec 4, 2008 at 7:01 PM
I've setup a basic project, and imports are working well enough, but I wanted to see if there was a way to have a second/third interface on a part that can optionally be called at runtime.

Is there any way to do that?

Thanks, Chris
Dec 4, 2008 at 8:30 PM

Hi Chris

Are you asking if you can have multiple exports on a part?

Glenn

From: szurgot [mailto:notifications@codeplex.com]
Sent: Thursday, December 04, 2008 12:01 PM
To: Glenn Block
Subject: Multiple Interfaces [MEF:41518]

From: szurgot

I've setup a basic project, and imports are working well enough, but I wanted to see if there was a way to have a second/third interface on a part that can optionally be called at runtime.

Is there any way to do that?

Thanks, Chris

Read the full discussion online.

To add a post to this discussion, reply to this email (MEF@discussions.codeplex.com)

To start a new discussion for this project, email MEF@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com

Dec 4, 2008 at 8:34 PM

Yes. But I only want to instantiate one copy of the part.

In particular, I want to add persistence functions, but not all parts need it, so I don’t want to have to implement those functions/properties.

Thanks, Chris

From: gblock [mailto:notifications@codeplex.com]
Sent: Thursday, December 04, 2008 1:31 PM
To: chris@szurgot.net
Subject: Re: Multiple Interfaces [MEF:41518]

From: gblock

Hi Chris

Are you asking if you can have multiple exports on a part?

Glenn

From: szurgot [mailto:notifications@codeplex.com]
Sent: Thursday, December 04, 2008 12:01 PM
To: Glenn Block
Subject: Multiple Interfaces [MEF:41518]

From: szurgot

I've setup a basic project, and imports are working well enough, but I wanted to see if there was a way to have a second/third interface on a part that can optionally be called at runtime.

Is there any way to do that?

Thanks, Chris

Read the full discussion online.

To add a post to this discussion, reply to this email (MEF@discussions.codeplex.com)

To start a new discussion for this project, email MEF@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com

Read the full discussion online.

To add a post to this discussion, reply to this email (MEF@discussions.codeplex.com)

To start a new discussion for this project, email MEF@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com

Dec 4, 2008 at 8:51 PM

You can have a single part that exports multiple contracts which will be shared by all exports. To do that you need to use the CompositionOptions attribute and specify that the part is a singleton. Once you do all it’s exports will use the same part instance.

Glenn

From: szurgot [mailto:notifications@codeplex.com]
Sent: Thursday, December 04, 2008 1:35 PM
To: Glenn Block
Subject: Re: Multiple Interfaces [MEF:41518]

From: szurgot

Yes. But I only want to instantiate one copy of the part.

In particular, I want to add persistence functions, but not all parts need it, so I don’t want to have to implement those functions/properties.

Thanks, Chris

From: gblock [mailto:notifications@codeplex.com]
Sent: Thursday, December 04, 2008 1:31 PM
To: chris@szurgot.net
Subject: Re: Multiple Interfaces [MEF:41518]

From: gblock

Hi Chris

Are you asking if you can have multiple exports on a part?

Glenn

From: szurgot [mailto:notifications@codeplex.com]
Sent: Thursday, December 04, 2008 12:01 PM
To: Glenn Block
Subject: Multiple Interfaces [MEF:41518]

From: szurgot

I've setup a basic project, and imports are working well enough, but I wanted to see if there was a way to have a second/third interface on a part that can optionally be called at runtime.

Is there any way to do that?

Thanks, Chris

Read the full discussion online.

To add a post to this discussion, reply to this email (MEF@discussions.codeplex.com)

To start a new discussion for this project, email MEF@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com

Read the full discussion online.

To add a post to this discussion, reply to this email (MEF@discussions.codeplex.com)

To start a new discussion for this project, email MEF@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com

Read the full discussion online.

To add a post to this discussion, reply to this email (MEF@discussions.codeplex.com)

To start a new discussion for this project, email MEF@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com

Dec 4, 2008 at 9:13 PM
Do you mean something like this??

[

CompositionOptions(CreationPolicy = CreationPolicy.Singleton)]
[
Export("Contract1"),Metadata_1(1)]
[
Export("Contract2"),Metadata_2(2)]
public class Part : IPart
{
}


Unfortunately I cat get this to work..



//lasse

 

Dec 4, 2008 at 9:15 PM

Yes, What is not working? Are you getting an exception?

Glenn

From: lassel [mailto:notifications@codeplex.com]
Sent: Thursday, December 04, 2008 2:14 PM
To: Glenn Block
Subject: Re: Multiple Interfaces [MEF:41518]

From: lassel

Do you mean something like this??

[

CompositionOptions(CreationPolicy = CreationPolicy.Singleton)]
[Export("Contract1"),Metadata_1(1)]
[Export("Contract2"),Metadata_2(2)]
public class Part : IPart
{
}


Unfortunately I cat get this to work..



//lasse

Read the full discussion online.

To add a post to this discussion, reply to this email (MEF@discussions.codeplex.com)

To start a new discussion for this project, email MEF@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com

Dec 4, 2008 at 9:45 PM

I was able to get this working, seemed to work pretty well.

Thanks, Chris

From: gblock [mailto:notifications@codeplex.com]
Sent: Thursday, December 04, 2008 2:15 PM
To: chris@szurgot.net
Subject: Re: Multiple Interfaces [MEF:41518]

From: gblock

Yes, What is not working? Are you getting an exception?

Glenn

From: lassel [mailto:notifications@codeplex.com]
Sent: Thursday, December 04, 2008 2:14 PM
To: Glenn Block
Subject: Re: Multiple Interfaces [MEF:41518]

From: lassel

Do you mean something like this??

[

CompositionOptions(CreationPolicy = CreationPolicy.Singleton)]
[Export("Contract1"),Metadata_1(1)]
[Export("Contract2"),Metadata_2(2)]
public class Part : IPart
{
}


Unfortunately I cat get this to work..



//lasse

Read the full discussion online.

To add a post to this discussion, reply to this email (MEF@discussions.codeplex.com)

To start a new discussion for this project, email MEF@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com

Read the full discussion online.

To add a post to this discussion, reply to this email (MEF@discussions.codeplex.com)

To start a new discussion for this project, email MEF@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com

Dec 4, 2008 at 9:48 PM

Cool. What was wrong?

From: szurgot [mailto:notifications@codeplex.com]
Sent: Thursday, December 04, 2008 2:46 PM
To: Glenn Block
Subject: Re: Multiple Interfaces [MEF:41518]

From: szurgot

I was able to get this working, seemed to work pretty well.

Thanks, Chris

From: gblock [mailto:notifications@codeplex.com]
Sent: Thursday, December 04, 2008 2:15 PM
To: chris@szurgot.net
Subject: Re: Multiple Interfaces [MEF:41518]

From: gblock

Yes, What is not working? Are you getting an exception?

Glenn

From: lassel [mailto:notifications@codeplex.com]
Sent: Thursday, December 04, 2008 2:14 PM
To: Glenn Block
Subject: Re: Multiple Interfaces [MEF:41518]

From: lassel

Do you mean something like this??

[

CompositionOptions(CreationPolicy = CreationPolicy.Singleton)]
[Export("Contract1"),Metadata_1(1)]
[Export("Contract2"),Metadata_2(2)]
public class Part : IPart
{
}


Unfortunately I cat get this to work..



//lasse

Read the full discussion online.

To add a post to this discussion, reply to this email (MEF@discussions.codeplex.com)

To start a new discussion for this project, email MEF@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com

Read the full discussion online.

To add a post to this discussion, reply to this email (MEF@discussions.codeplex.com)

To start a new discussion for this project, email MEF@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com

Read the full discussion online.

To add a post to this discussion, reply to this email (MEF@discussions.codeplex.com)

To start a new discussion for this project, email MEF@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com

Dec 4, 2008 at 9:53 PM

I’m not sure about lassel, but I has to put both interfaces on the actual class for it to work J As soon as I did that, a little refactoring to handle the new separation, and it worked pretty well.

Thanks, Chris

From: gblock [mailto:notifications@codeplex.com]
Sent: Thursday, December 04, 2008 2:49 PM
To: chris@szurgot.net
Subject: Re: Multiple Interfaces [MEF:41518]

From: gblock

Cool. What was wrong?

From: szurgot [mailto:notifications@codeplex.com]
Sent: Thursday, December 04, 2008 2:46 PM
To: Glenn Block
Subject: Re: Multiple Interfaces [MEF:41518]

From: szurgot

I was able to get this working, seemed to work pretty well.

Thanks, Chris

From: gblock [mailto:notifications@codeplex.com]
Sent: Thursday, December 04, 2008 2:15 PM
To: chris@szurgot.net
Subject: Re: Multiple Interfaces [MEF:41518]

From: gblock

Yes, What is not working? Are you getting an exception?

Glenn

From: lassel [mailto:notifications@codeplex.com]
Sent: Thursday, December 04, 2008 2:14 PM
To: Glenn Block
Subject: Re: Multiple Interfaces [MEF:41518]

From: lassel

Do you mean something like this??

[

CompositionOptions(CreationPolicy = CreationPolicy.Singleton)]
[Export("Contract1"),Metadata_1(1)]
[Export("Contract2"),Metadata_2(2)]
public class Part : IPart
{
}


Unfortunately I cat get this to work..



//lasse

Read the full discussion online.

To add a post to this discussion, reply to this email (MEF@discussions.codeplex.com)

To start a new discussion for this project, email MEF@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com

Read the full discussion online.

To add a post to this discussion, reply to this email (MEF@discussions.codeplex.com)

To start a new discussion for this project, email MEF@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com

Read the full discussion online.

To add a post to this discussion, reply to this email (MEF@discussions.codeplex.com)

To start a new discussion for this project, email MEF@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com

Read the full discussion online.

To add a post to this discussion, reply to this email (MEF@discussions.codeplex.com)

To start a new discussion for this project, email MEF@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com

Dec 5, 2008 at 12:49 PM
Hi


szurgot c
an you give a example ....


If I remove the first line ......   [Export("Contract1"),Metadata_1(1)]

the ExportCollection connected to this Export, contains "Part".  This means that it works.

If the line i present,, like the example earlier,  "Part" is missing from the same ExportCollection. 

One thing,,, I am still using Release 2 of MEF

 

/lasse
Dec 5, 2008 at 5:46 PM

Here’s what I’ve got:

   [CompositionOptions(CreationPolicy = CreationPolicy.Singleton)]

   [Export(typeof(TrayRunner.ITrayProgramPersistence))]

   [Export(typeof(TrayRunner.ITrayProgram))]

   public class MultiMon : TrayRunner.ITrayProgram, TrayRunner.ITrayProgramPersistence {

I’ve got both interfaces on the actual object, which I didn’t see in your example.

I am using release 3, so I don’t know if that’s all it’ll take.

Thanks, Chris

From: lassel [mailto:notifications@codeplex.com]
Sent: Friday, December 05, 2008 5:50 AM
To: chris@szurgot.net
Subject: Re: Multiple Interfaces [MEF:41518]

From: lassel

Hi


szurgot c
an you give a example ....


If I remove the first line ...... [Export("Contract1"),Metadata_1(1)]

the ExportCollection connected to this Export, contains "Part". This means that it works.

If the line i present,, like the example earlier, "Part" is missing from the same ExportCollection.

One thing,,, I am still using Release 2 of MEF



/lasse

Read the full discussion online.

To add a post to this discussion, reply to this email (MEF@discussions.codeplex.com)

To start a new discussion for this project, email MEF@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com

Dec 6, 2008 at 4:55 PM
Hi
Maby it is time to define,, "not working".

First,, I have changed to Release 3 of MEF,,, no difference. Second,,  I refactored my application to look like your example,, no difference,,, still "not working".

So what is "not working".

I have defined two ExportCollections like (I used your example) :

[

Import(typeof(typeof(TrayRunner.ITrayProgramPersistence))]
public ExportCollection<typeof(TrayRunner.ITrayProgramPersistence, IMetadata1> _1= null;

 

[

Import(typeof(TrayRunner.ITrayProgram))]
public ExportCollection<typeof(TrayRunner.ITrayProgram, IMetadata2> _2 = null;



Using your example above with MultiMon,,,

- If borth exports ,,,, both _1,,, and _2  is empty. I had expected one item in each eport collection.
- if [Export(typeof(TrayRunner.ITrayProgramPersistence))],,,,   _1 contains one item, _2 is empty.
-if [Export(typeof(TrayRunner.ITrayProgram))]  _2 contains one item, _1 is empty

 
My command over the englsih language is not so good, but I hope you understand what I am trying to say.

I will continue to dig into this,,, maby I have done some other misstake but,,, 

//lasse


 



  
Dec 10, 2008 at 5:37 PM
Edited Dec 10, 2008 at 5:40 PM
To summarize.

I've have tried to implement multiple interface metadata like :

[CompositionOptions(CreationPolicy = CreationPolicy.Singleton)]
[Export(typeof(IPart1)),Metadata_1(1)]
[Export(typeof(IPart2)),Metadata_2(2)]
public class Part : IPart1, IPart2
{
}


and

Import(typeof(IPart1)]
public ExportCollection<typeof(IPart1), IMetadata1> _collection1= null;

- In this example, _collection1 will be empty. Removing the export of IPart2, will give change the result,,,,, _collection1 will contain 1 item.

- If I remove the Metadata, _collection1 will contain one item.

I also modified the FileExplorer example by adding a extra Export with containing metadat to one of the modules... (AddressView)
The Import ( ExportCollection<UserControl, IFileExplorerViewMetadata> _view ) for connected to this Export was then reduced by 1.

So,,,, this leaves me with one question,,,, Am I using MEF wrongly or is there a bug??????????
I am very concerned for a answer.

//lasse



Dec 10, 2008 at 5:42 PM

I’ll look into it, but it might be a bug. Please go add a WorkItem.

Thanks

Glenn

From: lassel [mailto:notifications@codeplex.com]
Sent: Wednesday, December 10, 2008 10:38 AM
To: Glenn Block
Subject: Re: Multiple Interfaces [MEF:41518]

From: lassel

To summarize.

I've have tried to implement multiple interface metadata like :

[CompositionOptions(CreationPolicy = CreationPolicy.Singleton)]
[Export(typeof(IPart1)),Metadata_1(1)]
[Export(typeof(IPart2)),Metadata_2(2)]
public class Part : IPart1, IPart2
{
}


and

Import(typeof(IPart1)]
public ExportCollection<typeof(
IPart1), IMetadata1> _collection1= null;

- In this example, _collection1 will be empty. Removing the export of IPart2, will give the change the result, _collection1 will contain 1 item.

- If I remove the Metadata, _collection1 will contain one item.

I also modified the FileExplorer example by adding a extra Export with containing metadat to one of the modules... (
AddressView)
The Import (
ExportCollection<UserControl, IFileExplorerViewMetadata> _view ) for connected to this Export was then reduced by 1.

So,,,, this leaves me with one question,,,, Am I using MEF wrongly or is there a bug??????????
I am very concerned for a answer.

//lasse


Read the full discussion online.

To add a post to this discussion, reply to this email (MEF@discussions.codeplex.com)

To start a new discussion for this project, email MEF@discussions.codeplex.com

You are receiving this email because you subscribed to this discussion on CodePlex. You can unsubscribe or change your settings on codePlex.com.

Please note: Images and attachments will be removed from emails. Any posts to this discussion will also be available online at codeplex.com