Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Ok, so I know this is an old question, but I stumbled across this when trying to do the same thing, and it helped me get started - so I thought I would provide an answer.</p> <p>I think the code in the question was on the right track but there are a couple of problems. The interpolator was not completely initialised with the <code>ResourceManager</code> and <code>Culture</code> details, and it doesn't seem to allow for the fact that you can only have one <code>DefaultMessageInterpolator</code> per validation attribute. Also, you don't need an instance of the object you are validating to get an interpolated message.</p> <p>In the code in the question, where you are initialising the interpolator with the attribute value, you also need to initialise the interpolator with details of the <code>ResourceManager</code> to be used.</p> <p>This can be done using the overloaded <code>Initialize</code> method on <code>DefaultMessageInterpolator</code> which has the following signature:</p> <pre><code> public void Initialize(ResourceManager messageBundle, ResourceManager defaultMessageBundle, CultureInfo culture) </code></pre> <p>The first parameter is a user-defined ResourceManager in case you want to use your own resource file for error messages, you can pass a null if you just want to use the default ResouceManager, the second parameter is the default ResourceManager - you can pass </p> <pre><code> new ResourceManager( NHibernate.Validator.Cfg.Environment.BaseNameOfMessageResource, Assembly.GetExecutingAssembly()); </code></pre> <p>for this, the last parameter is the culture to use, (NHibernate.Validator comes with resource files with validation messages in several languages) - if you pass a null in to this it will just use <code>CultureInfo.CurrentCulture</code></p> <p>Lastly, you can only have one <code>DefaultMessageInterpolator</code> per attribute, so you will need to create a new <code>DefaultMessageInterpolator</code> for each validation attribute. You could make use of the <code>DefaultMessageInterpolatorAggregator</code> to handle this, or just roll your own.</p> <p>I hope this helps someone.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload