DI Container Example Configuration

Oct 10, 2006 at 10:24 PM
I was able to get a sample application working but I ran into a problem using the XML configuration. I haven't been able to figure out how to set up a generic mapping.

Here is an example where direct configuration seems to work but I can't get the XML configuration to work:
container.RegisterTypeMapping<IEntityMapper<Item>,ItemMapper>();
container.RegisterTypeMapping<IDataSetMapper<ItemDS>, ItemMapper>();
container.RegisterSingleton<ItemMapper>();

<ContainerConfig xmlns='container-config'>
<Mappings>
<Mapping FromType='IEntityMapper<Item>' ToType='ItemMapper' />
<Mapping FromType='IDataSetMapper<ItemDS>' ToType='ItemMapper' />
</Mappings>
<BuildRules>
<BuildRule Type='ItemMapper' Mode='Singleton' />
</BuildRules>
</ContainerConfig>

I get assert errors when it runs something like System.GetType("IDataSetMapper<ItemDS>">

If I ignore those, the type appears to be set up incorrectly.

What should my configuration look like?
Oct 10, 2006 at 11:28 PM
I don't think it is ideal but I found the answer to my question. It seems to work if I set the name of the generic type like "ItemMapper`1Item".

The key is a backtick, parameter ordinal and square brackets.
Oct 11, 2006 at 12:31 AM
Yep, that's how generics are represented in "string" form.