0
我想使用autofac IoC來初始化注入到MVC控制器構造函數中的服務。假設服務接口如下:在控制器構造函數中初始化服務
public interface IService
{
void SetValidationContainer(IReadOnlyDictionary<string, ModelStateEntry> validations);
}
和控制器的構造函數:
public class HelloWorldController : Controller
{
private readonly IService _service;
public HelloWorldController(IService service)
{
_service = service;
_service.SetValidationContainer(ModelState);
}
}
是否可以移動調用 「SetValidationContainer(ModelState中)」,以DI配置?而使用這樣的事情:
container.Register<IService>
.As<ServiceImplementaion>
.AfterInjectedInto<Controller>
.Call(service, controller => service.SetValidationContainer(controller.ModelState));