我正在使用Autofac进行依赖注入。
我在申请开始时有以下代码。
var builder = new ContainerBuilder();
builder.RegisterControllers(typeof(MvcApplication).Assembly);
builder.RegisterType(typeof(HolidayService)).AsImplementedInterfaces();
var container = builder.Build();
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
我有MVC控制器如下
public class MyController : Controller{
private IHolidayService _HolidayService;
public MyController (IHolidayService holidayService) {
//I want this constructor to be called**
this._HolidayService = holidayService;
}
private MyController () {
//but this constructor is called unfortunately
}
}
我希望调用参数化构造函数。但它调用默认构造函数。
如何调用参数化构造函数?