Definitions for the injector classes

Dec 20, 2011 at 12:31 AM
Edited Dec 20, 2011 at 12:37 AM

I took a look stab at providing definitions for the different injector classes. I was really lost until I did a review of the source code. I’m still not positive about some of these definitions, so please comment if you see any mistakes or omissions. Also, I put some questions in [ brackets ].

I'm hoping these will help other people out, and perhaps the developer (O) can use these in the documentation pages as well as in the "summary" documentation for each class.


* ValueInjection - the base injection class; contains an abstract Inject() method


* LoopValueInjectionBase - the base injection class for all loop injectors; contains a default implementation of AllowSetValue(), which always returns true, but can be overridden to allow, say, null values to be skipped

* PrefixedValueInjection – a base injection class for setting prefixes and searching for source/destination property names with prefixes stripped out (useful for flattening/unflattening scenarios)

* CustomizableValueInjection - a base injection class for scenarios where the source/destination types are not specified at compile time; contains a default implementation of TypesMatch() and SetValue()

* LoopValueInjection - the default injector; loops through each property of the source and checks if the destination has a property with the same name and type; if yes, the value is injected from the source to the destination

* LoopValueInjection<TSourceProperty, TTargetProperty> - a base loop injection class for defining mapping rules for a specific source and destination type (as with AutoMapper); contains an abstract SetValue() method

* ConventionInjection - a base loop injection class that allows custom logic for determining whether a source and destination match, and if they do, what value to inject; contains an abstract Match() method and a default implementation of SetValue()

* FlatLoopValueInjection - performs a "deep" loop injection that recursively searches source properties as well as properties of source properties (and deeper, if necessary) to find matches for destination properties based on prefixed names; e.g., the value of Address.ZipCode would be injected into AddressZipCode)

* FlatLoopValueInjection<TSourceProperty, TTargetProperty> - a base flattening injection class for defining mapping rules for a specific source and destination type (as with AutoMapper); contains an abstract SetValue() method

* UnflatLoopValueInjection – performs a "deep" loop injection that recursively searches prefixed source property names to find matches for destination properties and properties of destination properties (and deeper if necessary); e.g., the value of AddressZipCode would be injected into Address.ZipCode)

* UnflatLoopValueInjection<TSourceProperty, TTargetProperty> - a base unflattening injection class for defining mapping rules for a specific source and destination type (as with AutoMapper); contains an abstract SetValue() method

* KnownSourceValueInjection<TSource> - a base class for mapping from a known source to an unknown destination; contains an abstract Inject() method [ what is a good use case for this? ]

* KnownTargetValueInjection&lt;TTarget&gt; - a base class for mapping from an unknown source to a known destination; contains an abstract Inject() method [ what is a good use case for this? ]

* ExactValueInjection - a base class for injecting from a specific source property name to a specific destination property name; contains an abstract SourceName() and TargetName() method (useful for cases where no obvious convention exists for mapping a particular property and you want to avoid setting the property manually)

* NoSourceValueInjection - a base class for filling values of a particular object based on rules that have nothing to do with any source; contains an abstract Inject() method [ what is a good use case for this? ]

* SmartConventionInjection - a faster version of ConventionInjection that will be included in the next release (the current release is 2.3) [ will it simply replace ConventionInjection or will it go by the name "SmartConventionInjection"? ]

Coordinator
Dec 21, 2011 at 8:55 AM

you can see the usage for all of the injections in the demo solution

KnownSourceValueInjection and KnownTargetValueInjection have been used in WinForms and WebForms for injecting from and into the Form/ Page, also with the IDataReader

NoSourceValueInjection - I've used it to fill a test object with data, you can see that in prodinner also, I use it to test EF4 mappings

SmartConventionInjectionuseful

there's no need to replace injections, new ones can easily be added