ModelState Controller with ModelStateWrappper

HI, for everyone, I use the Structure Map to implement dependency injection. I created the ModelStateWrapper class to send the state of the model to the service level, which in the constructor receives a reference to the ModelState controller. In bootswrapper, I registered my type:

ForRequestedType<ISourceService>()
            .TheDefaultIsConcreteType<SourceService>();
ForRequestedType<IValidationDictionary>()
        .TheDefaultIsConcreteType<ModelStateWrapper>();

How can I give a link to the state of the controller model on ModelStateWrapper here?

ps sorry for my english :)

+3
source share
1 answer

You need to provide more information, but this is my best guess that you have:

public class ModelStateWrapper : IValidationDictionary
{
    ...
     private readonly ModelState _modelState;
     public ModelStateWrapper(ModelState modelState)
     {
          _modelState = modelState;
     }
    ...
}

( ) ModelStateWrapper, , ObjectFactory.

:

MyController : Controller 
{
   ...
   public MyAction()
   {
      ...
      IValidationDictionary validationDictionary = ObjectFactory
          .With<ModelState>(this.ModelState)
          .GetInstance<IValidationDictionary>();
      ...
   }
   ...
}

. :

StructureMap

+2

Source: https://habr.com/ru/post/1706511/


All Articles