Construtor/Setter Injection using IoC in HttpHandler, is it possible?

后端 未结 2 737
一个人的身影
一个人的身影 2021-01-18 14:53

I\'ve ran into a rather hairy problem. There is probably a simple solution to this but I can\'t find it!

I have a custom HttpHandler that I want to process a request

2条回答
  •  清酒与你
    2021-01-18 15:37

    Not possible, at least not directly. IHttpHandler objects are instantiated by the ASP.NET runtime and it doesn't allow Windsor to get involved in its creation. You can either:

    • Pull dependencies, by using the container as a service locator.
    • Set up a base handler that creates, injects and delegates to your own handlers (see how Spring does it)
    • Use the container as a service locator for another service that handles the entire request (as saret explained)

提交回复
热议问题