InjectionPropertyElement.PropertyType

Mar 25, 2008 at 5:05 PM
I realize this might be bordering on Getting Cute(TM), but I was wondering if it might be possible to automagically resolve the InjectionPropertyElement.PropertyType if none is provided?

It'd be nice to go from this:
<type type="SpyPolicy">
	<typeConfig extensionType="Microsoft.Practices.Unity.Configuration.TypeInjectionElement, Microsoft.Practices.Unity.Configuration">
		<property name="Enabled" propertyType="System.Boolean">
			<value value="true" />
		</property>							
	</typeConfig>
</type>

To this:
<type type="SpyPolicy">
	<typeConfig extensionType="Microsoft.Practices.Unity.Configuration.TypeInjectionElement, Microsoft.Practices.Unity.Configuration">
		<property name="Enabled" value="true" />							
	</typeConfig>
</type>

Also, since it looks like I can solve this through an configuration extension, it would be nice to alias extensionType's in configuration elements as well. :)
Mar 25, 2008 at 5:31 PM
I'd love to let you use aliases for extensionType, but System.Configuration fights you every step of the way. Basically, at deserialization time, you don't have access to anything other than the current element; there's no way to reach up in the XML tree and get that aliases section.

Ideally I'd like to be able to infer the property type, I just ran out of time.

Mar 25, 2008 at 5:57 PM
Well if type aliases were in a different configuration section, I imagine you'd be fine.

As for the property type being automatically resolved, I think it's just a matter of creating a new InjectionProperty that accepts the raw property value (from config) + a type converter and calls the converter only when the type gets resolved at "runtime" instead of calling the converter upfront at "config load time".

Makes sense?
Mar 25, 2008 at 7:00 PM


francois_tanguay wrote:
Makes sense?


Are you saying that you'd also provide a type converter in the configuration? That's extra work that I'm trying to get away from. :)
Mar 25, 2008 at 8:05 PM

francois_tanguay wrote:
Well if type aliases were in a different configuration section, I imagine you'd be fine.


Actually, it wouldn't help. The problem is: what if you're currently deserializing from a different file than the default configuration file? How would you know which file to read the typeAliases section from?
Mar 25, 2008 at 10:19 PM
Isn't that what EntLib's IConfigurationSource + ConfigurationSourceFactory "successfully" resolved?
Mar 26, 2008 at 12:17 AM
Yes, but then either: a) Unity has a dependency on Entlib (bad) or b) we copy giant swaths of code from entlib config into the Unity codebase. The latter idea made me quite ill, so we are where we are.