确保控制器具有无参数的公共构造函数error.Error有时为

时间:2016-11-17 10:24:47

标签: c# api asp.net-web-api autofac

在App_Start中

IContainer container = SetupDependencyInjection();

GlobalConfiguration.Configuration.DependencyResolver = new AutofacWebApiDependencyResolver(container);

 private IContainer SetupDependencyInjection()
    {
        var builder = new ContainerBuilder();
        builder.RegisterApiControllers(typeof(WebApiApplication).Assembly);
    builder.RegisterWebApiFilterProvider(GlobalConfiguration.Configuration);
        builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
        IContainer container = builder.Build();
        return container;
    }

这样做很好,但有时会显示错误 Error occurred when trying to create a controller of type 'ControllerName'. Make sure that the controller has a parameterless public constructor.

我是Web Api的新手。请帮帮我。

0 个答案:

没有答案