Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 767229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T17:10:43+00:00 2026-05-14T17:10:43+00:00

I have started writing my own WebDAV server class in .NET, and the first

  • 0

I have started writing my own WebDAV server class in .NET, and the first class I’m starting with is a WebDAVListener class, modelled after how the HttpListener class works.

Since I don’t want to reimplement the core http protocol handling, I will use HttpListener for all its worth, and thus I have a question.

What would the suggested way be to handle this:

  • Implement all the methods and properties found inside HttpListener, just changing the class types where it matters (ie. the GetContext + EndGetContext methods would return a different class for WebDAV contexts), and storing and using a HttpListener object internally
  • Construct WebDAVListener by passing it a HttpListener class to use?
  • Create a wrapper for HttpListener with an interface, and constrct WebDAVListener by passing it an object implementing this interface?

If going the route of passing a HttpListener (disguised or otherwise) to the WebDAVListener, would you expose the underlying listener object through a property, or would you expect the program that used the class to keep a reference to the underlying HttpListener?

Also, in this case, would you expose some of the methods of HttpListener through the WebDAVListener, like Start and Stop, or would you again expect the program that used it to keep the HttpListener reference around for all those things?

My initial reaction tells me that I want a combination. For one thing, I would like my WebDAVListener class to look like a complete implementation, hiding the fact that there is a HttpListener object beneath it.

On the other hand, I would like to build unit-tests without actually spinning up a networked server, so some kind of mocking ability would be nice to have as well, which suggests I would like the interface-wrapper way.

One way I could solve this would be this:

public WebDAVListener()
    : WebDAVListener(new HttpListenerWrapper())
{
}

public WebDAVListener(IHttpListenerWrapper listener)
{
}

And then I would implement all the methods of HttpListener (at least all those that makes sense) in my own class, by mostly just chaining the call to the underlying HttpListener object.

What do you think?

Final question: If I go the way of the interface, assuming the interface maps 1-to-1 onto the HttpListener class, and written just to add support for mocking, is such an interface called a wrapper or an adapter?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T17:10:43+00:00Added an answer on May 14, 2026 at 5:10 pm

    I’ll answer your last question first: a class is an adapter if it implements some ITarget interface using a contained object matching some ISource — an adapter from ISource to ITarget. In this case, there is no source interface, you’re trying to add one in, so I’d call it a wrapper.

    I’d be inclined to

    • Make a WebDavListener class which has all the methods it needs for its own behaviour, uses an HttpListener internally, and doesn’t expose anything about that HttpListener.

    • If and when you need it, make IHttpListenerWrapper and HttpListenerWrapper as you suggest, and change the WebDavListener to take an IHttpListenerWrapper in its constructor. Assuming all the methods are the same, this should be a simple search-and-replace. You could even leave the original constructor in there and have it construct a wrapper and call the new constructor.

    • If and when you need it, make an IWebDavListener for it to implement, if you think you might want a dummy WebDAV listener for unit testing other things.

    This sort of design issue is why I love refactoring tools like ReSharper: Extract Interface, Create Derived Implementation etc. make it much easier to make these sort of changes, so you can worry less about whether to do them now or later 🙂 (Assuming you are allowed to freely change the source later, of course, which depends how you’re delivering things.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just started writing my own JavaScript Framework (just for the learning experience),
I have started writing a Macro in Visual Studio 2005 like this: Public Sub
I'm writing a MVVM app and have started putting in a few animations. I
I have just installed C# 2008 Express Edition 2008 and started writing code. My
I have just started learning Jquery and am new to writing javascript (I am
I am just getting started couchdb and have been looking into writing couch apps.
I've recently started coding in C++, but I have long time writing in C.
I am developing a simple WinAPI application and started from writing my own assertion
I've started writing an interface for FedEx's webservice APIs. They have 3 different APIs
gcc 4.4.2 cmake 2.6 I have just started using cmake. Coming from writing my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.