title: passing around values to an AutoMapper Type Converter from outside
body: <p>I have a multilingual database, which returns values based on a key and an enum <code>Language</code>. When I convert a DB object to a model, I want the model to contain the translated value based on the key and the current language. </p>
  
  <p>The key comes from the DB object but how can I pass the current language to the the <code>Mapper.Map()</code> function? </p>
  
  <p>Currently, I am using a <code>[ThreadStatic]</code> attribute to set the culture before calling <code>Mapper.Map&lt;&gt;</code>, and to retrieve it in the <code>TypeConverter</code>.</p>
  
  <pre><code>public enum Language
  {
      English, French, Italian, Maltese
  }
  
  public class MultilingualValue&lt;T&gt;
  {
      public Dictionary&lt;Language, T&gt; Value { get; set; }
      public MultilingualValue()
      {
          this.Value = new Dictionary&lt;Language, T&gt;();
      }
  }
  
  public class PersonData
  {
      public string FirstName { get; set; }
      public MultilingualValue&lt;string&gt; City { get; set; }
  }
  
  public void MapPerson()
  {
      PersonData personData = new PersonData();
      personData.FirstName = "John";
      personData.City = new MultilingualValue&lt;string&gt;();
      personData.City.Value[ Language.English] = "The Zurrieq";
      personData.City.Value[Language.French] = "Le Zurrieque";
  
      MultilingualValueData.CurrentLanguage = Language.English; 
  
      var personModel = Mapper.Map&lt;PersonData, PersonModel&gt;(personData);
  }
  
  public class MultilingualValueToBasicDataTypeConverter&lt;T&gt; : ITypeConverter&lt;MultilingualValue&lt;T&gt;, T&gt; 
  {
      public T Convert(ResolutionContext context)
      {
          var currentLanguage = MultilingualValueData.CurrentLanguage; //THIS IS THE [ThreadStatic] VARIABLE
          if (currentLanguage == null) throw new InvalidOperationException("Please make sure to fill in CurrentLanguage");
  
          MultilingualValue&lt;T&gt; sourceMultilingualValue = (MultilingualValue &lt; T &gt; )context.SourceValue;
  
          T destinationValue = default(T);
          if (sourceMultilingualValue != null)
          {
              destinationValue = sourceMultilingualValue.Value[currentLanguage.Value];
          }
  
          return destinationValue;
      }
  }        
  
  public static class MultilingualValueData
  {
      [ThreadStatic]
      public static Language? CurrentLanguage;
  }
  </code></pre>
  
  <p>I left out the configurations as I think they're unneccessary for this example.  If you need them, I'll post them as well.</p>
  
  <p>While this works, I find this workaround quite ugly. Is there any way to pass data through the <code>ResolutionContext</code>?</p>