Possible Bug in Container Registrations

May 18, 2010 at 10:02 AM

Hi Chris

 

Just want ask if you have seen the issue I entered a while ago according to a possible bug in the Container Registrations.

http://unity.codeplex.com/WorkItem/View.aspx?WorkItemId=8153

 

Thanks for your Feedback.

Marco

May 20, 2010 at 9:27 PM

Yes, I've seen the issue. I'm not sure what you want me to say?

 

May 21, 2010 at 7:09 AM

Hi Chris

Sorry, if my post was unclear. Have you tried to run the test I posted?

I think the Container registrations do not work correctly for open generic types. If I register a mapping from 'IComponent<>' to 'Component<>' the Registration instance contains in the RegisteredType property the open generic type 'IComponent<>', but the MappedToType property contains some invalid information (for example the FullName of the Type returns an empty string). It seems that the type instance of the MappedToType property returns something like a half initialized type instance or so ... 

 

 

 

Jun 14, 2010 at 6:45 AM

Any updates on this?

Thanks Marco

Jun 14, 2010 at 10:19 PM

We've released Unity 2.0, and will put this on the backlog for fixing in the next version.

 

Jul 13, 2010 at 9:33 AM
marcoerni wrote:

Hi Chris

 

Just want ask if you have seen the issue I entered a while ago according to a possible bug in the Container Registrations.

http://unity.codeplex.com/WorkItem/View.aspx?WorkItemId=8153

 

Thanks for your Feedback.

Marco

Hi, marcoerni

I have a alterinative way to resolve this, but do not know if there is any other impact currently. Just modify "Map" method of the GenericTypeBuildKeyMappingPolicy.cs as follows:


public NamedTypeBuildKey Map(NamedTypeBuildKey buildKey, IBuilderContext context)
{
    Guard.ArgumentNotNull(buildKey, "buildKey");
    Type originalType = buildKey.Type;
    GuardSameNumberOfGenericArguments(originalType);

    if (originalType.IsGenericTypeDefinition)
    {
        return new NamedTypeBuildKey(destinationKey.Type, destinationKey.Name);
    }
    else
    {
        Type[] genericArguments = originalType.GetGenericArguments();
        Type resultType = destinationKey.Type.MakeGenericType(genericArguments);
        return new NamedTypeBuildKey(resultType, destinationKey.Name);
    }
}