C# Custom Attributes accessing database

1.7k views Asked by At

I have a custom attribute that accesses the database with nhiberate. The attribute actually inherits from Castle's AbstractValidationAttribute and is used to validate properties against regular expressions. Problem is, these regular expressions are cms managed and stored in the database, and when you change the values in the database, they are not reflected in the attribute. Basically, the attribute only initializes and there fore loads from the database once. Is there any way around this?

Thanks, Robin

2

There are 2 answers

4
Fredrik Mörk On

In my book it feels a bit odd to have an attribute perform database operations. That said, the attribute object is instantiated each time you call GetCustomAttributes for instance, so if the attribute picks up the data as part of its construction, it should fetch it whenever attributes are inspected using that method.

0
Michael Baldry On

Attributes generally don't do anything. They are markers. Other code should use them to perform some operation based on the data used in the attribute.