Selectors evaluate to either true or false. If the conditions exist that make a selector's criteria evaluate to true, then the mapping declared inside the selector is used.
Consider this example:
<ForService name="services/myDataServices" when="regen-time">
The ForService selector accepts an attribute called name. If the value of the name attribute matches the model ID of the Service Provider referenced in the Service Consumer model, then the mapping gets applied. The model ID is derived from the full path and filename of the Service Provider model. A full path and filename of a Service Provider model looks like this: WEB-INF\\models\\subfolders\\...\\filename.model
. The model ID omits the leading WEB-INF\\models\\
and the .model at the end of the filename. It also reverses the slashes. Therefore, a model located at WEB-INF\\models\\services\\myDataServices.model
has a model ID of services/myDataServices
There are other selectors that can be used in Service Mapping Registry files.
Always evaluates to true unless additional attributes are supplied. For example,
evaluates to true at regeneration time but false at runtime.
Uses a regular expression (RegEx) pattern matching value in an attribute named pattern. Service Providers whose model IDs match the pattern get replaced by the Service Providers declared in the mapping portion of the Selector. For example,
<ModifyName pattern="_testing" replacement="_production" />
Assuming a naming convention of Service Provider models that includes the substrings _testing
, this construct would swap all Service Providers whose model IDs contained the substring _testing
and replace them with the substring _production
. The actual models would not be changed, but any attempt to use a _testing
Service Provider would cause the corresponding _production
Service Provider to be used instead.
Relies on mapping parameters declared in the Service Consumer builder call of the application model. This construct designates which Service Provider to use when certain name-value pairs exist in the Service Consumer model. For example, the construct below states for any attempt to use the services/myDataServices
provider model, check to see if there is a mapping parameter called mode having a value of testing or production and swap the Service Provider accordingly. If no mapping parameter exists or if the value of the parameter does not match either value, then the services/myDataServices
Service Provider model should be used.
<IfParameterEquals name="mode" value="testing">
<UseService name="services/myDataServices_testing" />
<IfParameterEquals name="mode" value="production">
<UseService name="services/myDataServices_production" />
<UseService name="services/myDataServices" />
Parent topic: Using data services: wpf7