Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HttpContext vs HttpListenerContext

Tags:

.net

http

iis

While porting a webapp from IIS/asp.net to HttpListener something struck me as rather strange.

While both have a concept of Context, Request and Response, the HttpListener variants share no common interface with the IIS/asp.net variants, despite the fact that the interfaces are almost identical.

In order to work around this, I have created my own common interfaces (IContext,IRequest and IResponse) and wrapped the corresponding server generated objects with implementations of these interfaces, so that I don't need two separate implementations of the handler code that I am porting.

This has resulted in a class explosion of wrappers (10 in all), just to code around this missing common interface.

Have I missed a trick, or is this just a shortcoming of the .net APIs?

like image 844
spender Avatar asked Mar 10 '09 15:03

spender


1 Answers

I would say the whole HttpContext has this shortcoming. It is the same situation that happens when adding unit tests, you wrap those to be able to replace with mocks in the unit tests.

like image 184
eglasius Avatar answered Nov 15 '22 00:11

eglasius