views:

17

answers:

1

I have an abstract domain object that is consumed by both a web and windows application. This domain object sits in a an old namespace along with any derived classes.

For my web application I would like to use data annotations. Usually I would create a partial class to the domain object and provide it a MetaData class. However, I am unable to touch the namespace where the domain objects reside and there lies my problem.

Is there any solution for providing partial classes/metadata to domain objects in another namespace? Remember I can't touch the domain objects namespace at all.

A: 

DataAnnotations works by decorating properties on a type with attributes, or by decorating the actual type with a MetadataTypeAttribute that points at the actual class that holds the validation attributes.

If you can't touch it, you can't use DataAnnotations. It's as simple as that. You might try try some code weaving technique such as CCI to change the assembly without touching the code, but in the end you are still touching it.

You need to pick a different validation framework. One that allows to separate the validation configuration completely from the actual code: You clearly need Enterprise Library Validation Application Block, because it allows you to put the validations in a (XML) configuration file.

Good luck.

Steven
Thought as much. Thanks. I even tried creating a partial class in a different assembly but with same namespace as the domain object and then applying the MetdataTypeAttribute on the partial class but then there were compile errors about ambiguity. I'll take a look at Enterprise Library Validation Application Block.
David Liddle