I would like to solicit a change with regard to the ability to remove the HttpControllerDispatcher in web hosting scenarios. It would be nice to have the ability to completely remove the dispatcher to engender light weight proxy, api-management, etc. scenarios.
Typically, with these use cases there is not a need for an entire framework; however, the ability to leverage the message handling infrastructure is still valuable - think rack or node's connect.
Is there a reason this is not possible?
If I am missing something, please let me know. Also, I do understand this is possible in self-hosting scenarios.
I would like to pass in a custom HttpMessageHandler dispatcher to
HttpServer. This would allow me to have a custom message handler as the first handler in the pipeline.
Currently, in the web-host scenario this is not possible. There is not a IoC service for the dispatcher and the GlobalConfiguration.Dispatcher property is readonly to name a few hurdles.
I do understand this is possible if I write my own asp.net webapi host. But, it would be great if this extensibility comes out of the box.
I have also voted for this. But for now (for testing purpose only) we can use reflection hack,
public class MyHttpControllerDispatcher : HttpControllerDispatcher
{
public MyHttpControllerDispatcher(HttpConfiguration h)
: base(h)
{
}
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken ct)
{
return base.SendAsync(request, ct);
}
}
var _configuration = (Lazy<HttpConfiguration>)typeof(GlobalConfiguration).GetField("_configuration", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null);
var ob = new Lazy<HttpControllerDispatcher>(() => new MyHttpControllerDispatcher(_configuration.Value));
typeof(GlobalConfiguration).GetField("_dispatcher", BindingFlags.Static | BindingFlags.NonPublic).SetValue(null,ob);
"And whoever is removed away from the Fire and admitted to Paradise, he indeed is successful." (The Holy Quran)
Excellent Windows VPS Hosting Imran Baloch MVP, MVB, MCP, MCTS, MCPD
davebettin
Member
313 Points
94 Posts
Removing HttpControllerDispatcher
Mar 05, 2012 04:39 PM|LINK
I would like to solicit a change with regard to the ability to remove the HttpControllerDispatcher in web hosting scenarios. It would be nice to have the ability to completely remove the dispatcher to engender light weight proxy, api-management, etc. scenarios. Typically, with these use cases there is not a need for an entire framework; however, the ability to leverage the message handling infrastructure is still valuable - think rack or node's connect.
Is there a reason this is not possible?
If I am missing something, please let me know. Also, I do understand this is possible in self-hosting scenarios.
Thanks,
Dave
@dbettin
marcind
Contributor
3344 Points
609 Posts
Microsoft
Re: Removing HttpControllerDispatcher
Mar 05, 2012 09:48 PM|LINK
Could you elaborate on how it's not possible to remove it now? Maybe provide some examples of the code you would like to be able to write.
ASP.NET Team
@marcind
Blog
davebettin
Member
313 Points
94 Posts
Re: Removing HttpControllerDispatcher
Mar 06, 2012 02:09 AM|LINK
Sure.
I would like to pass in a custom HttpMessageHandler dispatcher to HttpServer. This would allow me to have a custom message handler as the first handler in the pipeline.
Currently, in the web-host scenario this is not possible. There is not a IoC service for the dispatcher and the GlobalConfiguration.Dispatcher property is readonly to name a few hurdles.
I do understand this is possible if I write my own asp.net webapi host. But, it would be great if this extensibility comes out of the box.
Thanks,
Dave
@dbettin
CarlosFiguei...
Member
99 Points
19 Posts
Microsoft
Re: Removing HttpControllerDispatcher
Mar 12, 2012 08:29 AM|LINK
Hi Dave,
I tried doing something similar with the webhosted APIs, and didn't quite get the simplicity of the self-host case, but that's one start. Is that along the lines of what you were looking for? The post is at http://blogs.msdn.com/b/carlosfigueira/archive/2012/03/12/lightweight-webhosted-services-with-asp-net-web-api.aspx.
Thanks,
Carlos.
davebettin
Member
313 Points
94 Posts
Re: Removing HttpControllerDispatcher
Mar 12, 2012 04:55 PM|LINK
Carlos. Thanks for following up. That is a too much ceremony for what I had in mind.
I created a user voice thread for this feature request: http://aspnet.uservoice.com/forums/147201-web-api/suggestions/2674946-replace-dispatcher-in-web-host-scenarios.
Thanks,
Dave
@dbettin
imran_ku07
All-Star
45815 Points
7698 Posts
MVP
Re: Removing HttpControllerDispatcher
Mar 30, 2012 07:54 PM|LINK
I have also voted for this. But for now (for testing purpose only) we can use reflection hack,
public class MyHttpControllerDispatcher : HttpControllerDispatcher { public MyHttpControllerDispatcher(HttpConfiguration h) : base(h) { } protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken ct) { return base.SendAsync(request, ct); } } var _configuration = (Lazy<HttpConfiguration>)typeof(GlobalConfiguration).GetField("_configuration", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null); var ob = new Lazy<HttpControllerDispatcher>(() => new MyHttpControllerDispatcher(_configuration.Value)); typeof(GlobalConfiguration).GetField("_dispatcher", BindingFlags.Static | BindingFlags.NonPublic).SetValue(null,ob);Excellent Windows VPS Hosting
Imran Baloch MVP, MVB, MCP, MCTS, MCPD