Suppose I have a ASP.NET Web API controller that uses a service, which in turn depends on HttpControllerContext to perform some processing.
public class MyApiController : ApiController {
IMyService _service;
MyApiController(IMyService service) {
_service = service;
}
public void Post(Resource resource) {
_service.Process(resource);
}
}
public interface IMyService {
void Process(Resource resource);
}
public class MyService : IMyService {
HttpControllerContext _controllerContext;
MyService(HttpControllerContext controllerContext) {
_controllerContext = controllerContext;
}
public void Process(Resource resource) {
// use _controllerContext and process resource
}
}
How does one configure Unity to inject an instance of HttpControllerContext when MyService is created? I am unable to find a way to get the HttpControllerContext used by the controller to be “injected” into the instance of MyService so it can use it.
Have a look at Mark Seemann’s post on how to wire HttpControllerContext with Castle Windsor. Unity should work similar.