0

I try to integrate autofac for webapi and I am having problem to make it work. My controller constructor signature is:

public class AController: ApiController
{
  public AController(IComponentContext componentContext)
  {}
}

In my global.asax file i have called the following code in Application_Start

protected void Application_Start()
{
   var builder = new ContainerBuilder();
   builder.RegisterApiControllers();
   container = builder.Build();
   var resolver = new AutofacWebApiDependencyResolver(container);
   GlobalConfiguration.Configuration.DependencyResolver = resolver;

}

When I try to run my application and to access my ressource "/api/A", the server returns an error 500 complaining about the fact the controller does not have a default constructor. I though that was the task of the AutofacWebApiDependencyResolver to inject the container in my case. How can I fix my issue ?

Thanks,

1 Answer 1

2

I have found my issue .

Update this line to

builder.RegisterApiControllers(Assembly.GetExecutingAssembly()); 

sort the issue out.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.