I found the solution to my problem. Actualy the steps needed are almost the same as when setting the autofac with web api hosted in the IIS. So to set-up the autofac with the self-hosted web api follow the next steps:
- download the Autofac.WebApi nuget package
- set the the autofac builder as you normally would
- the only difference is whan you have to assign the autofac as a dependency resolver to the web api. GlobalConfiguration is not accessible in the self-hosted scenario so you just use the DependencyResolver property on the HttpSelfHostConfiguration instance:
var builder = new ContainerBuilder();
var container = builder.Build();
var resolver = new AutofacWebApiDependencyResolver(container);
var config = new HttpSelfHostConfiguration(@"http://localhost:9099");
config.DependencyResolver = resolver;
var server = new HttpSelfHostServer(config);