Reputation: 1399
HI, to all, i am use Structure Map to implement dependency-injection. I created ModelStateWrapper class to send Model state in service layer, which in constructor get reference to ModelState of controller. In bootswrapper i registered my type:
ForRequestedType<ISourceService>()
.TheDefaultIsConcreteType<SourceService>();
ForRequestedType<IValidationDictionary>()
.TheDefaultIsConcreteType<ModelStateWrapper>();
How i can give reference of controller's model state to ModelStateWrapper here ?
p.s. sorry for my english :)
Upvotes: 3
Views: 1060
Reputation: 13521
You need to provide more information, but this is my best guess as to what you have:
public class ModelStateWrapper : IValidationDictionary
{
...
private readonly ModelState _modelState;
public ModelStateWrapper(ModelState modelState)
{
_modelState = modelState;
}
...
}
If you want to pass a variable (the controller's model state in this case) to the ModelStateWrapper you almost certainly need to do that explicitly by calling the ObjectFactory.
Example:
MyController : Controller
{
...
public MyAction()
{
...
IValidationDictionary validationDictionary = ObjectFactory
.With<ModelState>(this.ModelState)
.GetInstance<IValidationDictionary>();
...
}
...
}
See this documentation for details:
Passing Arguments to StructureMap at Runtime
Upvotes: 2