Account Options

  1. Sign in
The old Google Groups will be going away soon.
Switch to the new Google Groups.
Google Groups Home
« Groups Home
MEF registered types with dependencies on non MEF registered types doesn't work
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  5 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Shandem  
View profile  
 More options Nov 25 2010, 1:51 am
From: Shandem <sdemin...@gmail.com>
Date: Wed, 24 Nov 2010 22:51:01 -0800 (PST)
Local: Thurs, Nov 25 2010 1:51 am
Subject: MEF registered types with dependencies on non MEF registered types doesn't work
Hi,

Say i have an object in my main DLL:

TestData

then i register this type in my container:
builder.RegisterType<TestData>()

Say i have an object in my plugins DLL:

[Export]
public class MyObject {
   public MyObject(TestData testData) {...}

}

then i register my plugins DLL:
var catalog = new DirectoryCatalog(m_HttpServer.MapPath("~/Plugins/
Stuff"));
builder.RegisterComposablePartCatalog(catalog);

when i resolve MyObject, it tells me that:

The request service 'ContractName=TestData' has not been registered.

I've looked in the source of Autofac and it appears as though
ComponentsForContract it checks if components are registered using the
RegistrationsFor method. Inside of that method, it ONLY looks for
services that are of type:
ContractBasedService

Unfortunately, the TestData service isn't registered as a
ContractBased service and only as a TypedService because it wasn't
registered using the MEF extensions.

A 'workaround' which does work is to register my test service 2 times
and mark it with an Export attribute:

builder.RegisterType<TestData>()
builder.RegisterComposablePartType(typeof(TestData));

This DOES work but is not really ideal.

Is there any reason why Autofac forces the search for dependencies on
MEF components to be ContractBasedService ?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Nicholas Blumhardt  
View profile  
 More options Nov 25 2010, 4:33 pm
From: Nicholas Blumhardt <nicholas.blumha...@gmail.com>
Date: Fri, 26 Nov 2010 07:33:57 +1000
Local: Thurs, Nov 25 2010 4:33 pm
Subject: Re: MEF registered types with dependencies on non MEF registered types doesn't work

Hi Shandem,

You need to mark the TestData type:

builder.RegisterType<TestData>()
    .Exported(x => x.As<TestData>());

There are differences between the way MEF and Autofac handle service
contracts that make this necessary for a correct integration. Given that the
exported types form the "public" extensibility API of your application, it
is probably not a bad idea to select them explicitly anyway.

Cheers,
Nick

On 25 November 2010 16:51, Shandem <sdemin...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Shandem  
View profile  
 More options Nov 25 2010, 8:38 pm
From: Shandem <sdemin...@gmail.com>
Date: Thu, 25 Nov 2010 17:38:42 -0800 (PST)
Local: Thurs, Nov 25 2010 8:38 pm
Subject: Re: MEF registered types with dependencies on non MEF registered types doesn't work
Ok great, but if i register TestData like the above, will it be able
to be injected into non-MEF dependencies as well?

Thanks,
Shannon

On Nov 26, 8:33 am, Nicholas Blumhardt <nicholas.blumha...@gmail.com>
wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Nicholas Blumhardt  
View profile  
 More options Nov 25 2010, 10:03 pm
From: Nicholas Blumhardt <nicholas.blumha...@gmail.com>
Date: Fri, 26 Nov 2010 13:03:41 +1000
Local: Thurs, Nov 25 2010 10:03 pm
Subject: Re: MEF registered types with dependencies on non MEF registered types doesn't work

Yes.

Cheers,
Nick

On 26 November 2010 11:38, Shandem <sdemin...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Shandem  
View profile  
 More options Nov 25 2010, 11:41 pm
From: Shandem <sdemin...@gmail.com>
Date: Thu, 25 Nov 2010 20:41:20 -0800 (PST)
Local: Thurs, Nov 25 2010 11:41 pm
Subject: Re: MEF registered types with dependencies on non MEF registered types doesn't work
Amazing. thanks for the tip, works perfectly!

On Nov 26, 2:03 pm, Nicholas Blumhardt <nicholas.blumha...@gmail.com>
wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »