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 906721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:26:07+00:00 2026-05-15T16:26:07+00:00

At work, I’ve found a helper class to manage WCF Services which implements IDisposable

  • 0

At work, I’ve found a helper class to manage WCF Services which implements IDisposable and has a ServiceAgent that derives from System.ServiceModel.ClientBase. The Dispose() method closes all the opened WCF services. The helper exposes methods that wraps calls to the methods of the ServiceAgent. Each method is build on that pattern:

public void WCFMethod1()
{
    using(this)
    {
        this.ServiceAgent.WCFMethod1();
    }
}

public override void Dispose()
{
    try
    {
        this.ServiceAgent.Close();
    }
    catch
    {
        this.ServiceAgent.Abort();
    }
    finally
    {
        this.ServiceAgent = null;
    }
}

Here’s the question: is the use of using(this) a good practice?

  • 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-15T16:26:08+00:00Added an answer on May 15, 2026 at 4:26 pm

    I don’t like it. I think that class should be a) disposed once b) by code that instantiated it. IDisposable usually understood as way to implement RAII pattern. MSDN explicitly states:

    If an object’s Dispose method is
    called more than once, the object must
    ignore all calls after the first one.
    The object must not throw an exception
    if its Dispose method is called
    multiple times. Instance methods other
    than Dispose can throw an
    ObjectDisposedException when resources
    are already disposed.

    So users will find this behavior confusing, so i recommend to design the class so that it is instantiated per call:

    using (var clientFactory = new ClientFactory())
       clientFactory.Client.WCFMethod1();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I work for a .NET/MSSQL shop that has trouble supporting customers running Novell, partially
At work, we're working on a dozen Java OSGi bundles, each of which has
At work, we have multiple branches that we may be working on at any
I work for a small agency that works mainly with php, and we were
At work, We use a pretty old browser(symbol's pocket browser) that supports only JS
I have to work with text that was previously copy/pasted from an excel document
At work we are currently still using JUnit 3 to run our tests. We
At work we are being asked to create XML files to pass data to
I work in VBA, and want to parse a string eg <PointN xsi:type='typens:PointN' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
I work with C# at work but dislike how with webforms it spews out

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.