kanayabhattad / autofac

Automatically exported from code.google.com/p/autofac
Other
0 stars 0 forks source link

RegisterAdapter does not propagate keys or names from TFrom to TTo; and there is no way to do so #482

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
The attached xunit test case reproduces the problem.  I've also documented the 
problem and a workaround on stackoverflow: 
http://stackoverflow.com/questions/20985715/in-autofac-how-do-i-propagate-keys-t
hrough-adapters/21009633

What is the expected output? What do you see instead?

I would expect that RegisterAdapter() propagates keys from TFrom to TTo; as it 
does propagate Metadata from TFrom to TTo.  It's possible that not doing so is 
a design decision, but I'm not able to figure out why.

What version of Autofac are you using? On what version of .NET/Silverlight?

Autofac 3.2.0 on .NET 4.5

Original issue reported on code.google.com by john.c...@gmail.com on 9 Jan 2014 at 12:58

GoogleCodeExporter commented 8 years ago
Here's the xunit test case code.  It wasn't clear that I had to attach it 
before submitting the issue.

Original comment by john.c...@gmail.com on 9 Jan 2014 at 1:02

Attachments:

GoogleCodeExporter commented 8 years ago

Original comment by travis.illig on 10 Jan 2014 at 1:11

GoogleCodeExporter commented 8 years ago
The services registered with Named are added as KeyedService, but those 
registered with the RegisterAdapter function are added as TypedService.

Because a KeyedService requires a key, and the adapter function can't provide 
the key for all the different registrations, there is no way to have it create 
the required KeyedService as registration time.

I had a look at this tonight and couldn't find an easy way to solve the issue. 
I'll leave this open for now and take another look when I'm a bit less tired.

Original comment by alex.meyergleaves on 10 Jan 2014 at 1:37

GoogleCodeExporter commented 8 years ago
Would it be possible to create a function similar to .RegisterAdapter() that 
takes a KeyedService and returns a new KeyedService based on all registered 
KeyedServices for the input type using an IRegistrationSource?  Eg 
RegisterKeyedServiceAdapter<TIn, TOut>()?  I looked into trying this (mainly 
reading the code for RegisterAdapter() and friends, and reading about 
IRegistrationSource), and it seemed possible, but more work/maintenance than I 
was able to afford at the time.  And I'm relatively new to autofac, so my 
judgement on such things isn't well informed.

Or alternatively, would it be possible to add an extension method the 
RegisterAdapter()'s return type, ala:
  builder.RegisterAdapter<TIn, TOut>(adapter func ...).AdaptKeys(key1, key2, key3)
and/or:
  builder.RegisterAdapter<TIn, TOut>(adapter func ...).AdaptAllKeys()

Original comment by john.c...@gmail.com on 13 Jan 2014 at 12:46

GoogleCodeExporter commented 8 years ago
Moved issue to GitHub: https://github.com/autofac/Autofac/issues/482

Subsequent issue management will be held there; closing the issue on Google 
Code as "WontFix" because we will handle issue resolution on GitHub.

Original comment by travis.illig on 11 Feb 2014 at 12:01

GoogleCodeExporter commented 8 years ago

Original comment by travis.illig on 11 Feb 2014 at 12:01