Here’s a neat little trick I’ve recently learnt that my favourite IoC container can do.
First register the subsystem with the AddSubSystem method, passing in a new instance of the NamingPartsSubSystem.
You can then give your components names differentiated by any number of parameters. For example we can have several components with the base name ‘thing’ and with a comma separated list of properties, in our case colour and version. The syntax is:
<name>:<key 1>=<value 1>[,<key n>=<value n>]
We can now resolve components based on any combination of those parameters. If more than one component matches, the container simply returns the first one to be registered.
Here’s a little test to demonstrate: