I have the following WebAPI Controller (I have removed most of the code for brevity)
public class ConnectionController : ApiController
{
/// <summary>
/// Gets or sets the connection manager.
/// </summary>
/// <value>
/// The connection manager.
/// </value>
public IConnectionManagerService ConnectionManager
{
get;
set;
}
}
I am trying to insert the IConnectionManagerService through AutoFac and this is the code I have so far
// Create the container builder.
var builder = new ContainerBuilder();
// Register the Web API controllers.
builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
// Register other dependencies.
builder.Register(c => new ConnectionManagerService()).As<IConnectionManagerService>().InstancePerRequest();
// Build the container.
var container = builder.Build();
// Create the depenedency resolver.
var resolver = new AutofacWebApiDependencyResolver(container);
// Configure Web API with the dependency resolver.
GlobalConfiguration.Configuration.DependencyResolver = resolver;
Now inside the controller when I try to Use ConnectionManager I get null. I thought Autofac will automatically include the dependency? I dont want to include this dependency through a constructor parameter in the controller.