Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to automatically set properties on view model with StructureMap
    primarykey
    data
    text
    <p>I have an interface ITranslateStuff and a static class and method with a generic parameter that is constrained (where class, ITranslateStuff, new()).</p> <pre><code>string translation = Translator.TranslateStuff&lt;ITranslateStuff&gt;(); </code></pre> <p>Depending on which implementation of ITranslateStuff that I pass the method returns a different string.</p> <p>I have ViewModels with a lot of different properties wich returns implementations of ITranslateStuff, for example:</p> <pre><code>public class ExampleViewModel { public string OtherStuff {get; set; } public string TranslateStuffExample1 Translations { get; set; } public ExampleViewModel2 SubModel {get; set; } } public class ExampleViewModel2 { public string MoreStuff { get; set; } public string TranslateStuffExample2 Translations { get; set; } } </code></pre> <p>where both DoStuffExample1 and DoStuffExample2 implements ITranslateStuff.</p> <p>I'm currently populating all theese properties with code like this:</p> <pre><code>model.Translations = Translator.TranslateStuff&lt;TranslateStuffExample1&gt;(); model.SubModel.Translations = Translator.TranslateStuff&lt;TranslateStuffExample2&gt;(); </code></pre> <p>In the project we use StructureMap. I want to avoid setting all the properties on my view model manually with the same static method call. I have an ActionFilter where I set common properties on my view model, and was thinking I want to do this in an action filter as well.</p> <p>I've tried finding something in StructureMap that can do this for me.</p> <p>How can I solve this?</p>
    singulars
    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. 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