You will want to use 'setter injection'.
http://docs.structuremap.net/ConstructorAndSetterInjection.htm#section4
Domanda
I have an interface ITranslateStuff and a static class and method with a generic parameter that is constrained (where class, ITranslateStuff, new()).
string translation = Translator.TranslateStuff<ITranslateStuff>();
Depending on which implementation of ITranslateStuff that I pass the method returns a different string.
I have ViewModels with a lot of different properties wich returns implementations of ITranslateStuff, for example:
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; }
}
where both DoStuffExample1 and DoStuffExample2 implements ITranslateStuff.
I'm currently populating all theese properties with code like this:
model.Translations = Translator.TranslateStuff<TranslateStuffExample1>();
model.SubModel.Translations = Translator.TranslateStuff<TranslateStuffExample2>();
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.
I've tried finding something in StructureMap that can do this for me.
How can I solve this?
Soluzione
You will want to use 'setter injection'.
http://docs.structuremap.net/ConstructorAndSetterInjection.htm#section4