2
我希望能夠將模型狀態注入到服務中。Autofac - 將ModelState注入服務
服務
public ThirdPartyService(IValidationDictionary dict)
{
// IValidationDictionary, in this case is a ModelStateWrapper object
// I created to wrap model state
}
註冊
builder.Register(x => new ModelStateWrapper(x.Resolve<ControllerType>().ViewData.ModelState))
.As<IValidationDictionary>().InstancePerHttpRequest();
任何想法?