Reputation: 17804
As the title states: what (if available) is the replacement for the <typeConfig />
element in Unity 2?
Or alternatively: How can I configure a type parameter for a class in Unity configuration?
<alias alias="ISomeInterface" type="Namespace.ISomeInterface" />
<alias alias="SomeType" type="Namespace.SomeType`1" />
<alias alias="Foo" type="Namespace.Foo" />
<alias alias="Bar" type="Namespace.Bar" />
<container>
<register type="ISomeInterface" mapTo="SomeType" name="GenericFoo">
<!-- define generic type as Foo -->
</register>
<register type="ISomeInterface" mapTo="SomeType" name="GenericBar">
<!-- define generic type as Bar -->
</register>
</container>
Upvotes: 1
Views: 499
Reputation: 30411
The <typeConfig> element was simply removed - it was a layer of XML that didn't actually add anything but noise to the config file. The stuff that you previously nested inside typeConfig (like <constructor>, <param>, etc.) are now placed as children of the <register> element.
As for your example there, you'd need to specify the generic type parameter as part of the mapTo parameter, like so:
<register type="ISomeInterface" mapTo="SomeType[Foo]" name="GenericFoo" />
<register type="ISomeInterface" mapTo="SomeType[Bar]" name="GenericBar" />
Or you could use the CLR generic type syntax (the version with the `1 etc.) but that's a lot noisier than the shortcut syntax Unity implements here.
NOTE: Of course, the aliases you have above won't work, since you haven't included the assembly names with them, so this solution won't work until you work out those details. Also, consider using the <assembly> and <namespace> declarations in the config file to remove the need for lots of aliases.
Upvotes: 2