Arbitrary model metadata provider caching issue

So that we can dynamically manage labels and error messages, we created a custom DataAnnotationsModelMetadataProvider

. In the attribute, Display

we store the key in the property Name

and using the custom one DataAnnotationsModelMetadataProvider

, we substitute the key for the string value from our custom CMS. The problem is that we now have two sets of values. One for web views and one for mobile views. At runtime, we check to see if the client is on a mobile device and substitute the values ​​accordingly.

After testing this setup, I ran into some strange problem. When first created AppDomain

and the properties of Name

various data annotations are replaced with string values, everything works fine. On debugging, when I enter custom DataAnnotationsModelMetadataProvider

a second time, I see that the name properties are already populated with values ​​which I replaced with the previous run. This was strange to me since I realized that data annotation predictions could not be used at runtime. It seems there is a model metadata cache somewhere. Since I was basing my custom solution on replacing the values ​​every time it is called DataAnnotationsModelMetadataProvider

, I would like to disable this caching if possible.

Currently I started using property ShortName

as a key persistence property and I am replacing the property Name

so that I can repopulate the rows for each run. But that was not the original design and I don't have such a keystore for ValidationAttributes

.

So, is there a way to disable this cache? I don't need a cache for caching as all CMS data is cached in memory at a different level.

+3


source to share





All Articles