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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:38:13+00:00 2026-05-22T18:38:13+00:00

I have a third party C# library for ldap operations. It does all operations

  • 0

I have a third party C# library for ldap operations. It does all operations on connection object as below:

LdapConnection connection = new LdapConnetion(Settings settings);
connection.Search(searchOU, filter,...);

which I feel is not readable. I want to write a wrapper around it so that I should be able to write code like below:

As I would like to have different Ldap classes like

public class AD: LdapServer { }
public class OpenLdap: LdapServer { }

and then

AD myldap = new AD(Settings settings);
myldap.Users.Search(searchOU, filter,...)
myldap.Users.Add(searchOU, filter,...)
myldap.Users.Delete(searchOU, filter,...)

I am thinking about Proxy design pattern, but things are not getting into my head about hot to go about it. What classes should I have etc.

Any help?

  • 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-22T18:38:14+00:00Added an answer on May 22, 2026 at 6:38 pm

    The solution posted above inherits from the LdapConnection. This is good if you want to maintain the inheritance chain, but I dont think that is necessary in your case. You simply want to customize and simplify the interface.

    The proxy design pattern inherits from the underlying object so that the proxy object can be used anywhere that the underlying object is required, this is good if you want to “inject” extra functionality into the class without the clients of that class realising. I dont think this is your intention here?

    The big problem with the solution posted above is that (because it inherits directly from LdapConnection) you can call search in two ways like so:

    Settings settings = new Settings();
    AD myAD = new AD(settings);
    
    object results = myAD.Users.Search();
    // OR
    object results2 = myAD.Search();
    

    As I’m sure you can see from the code, both of these call the exact same underlying method. But in my opinion, this is even more confusing to developers than just using the vanilla LdapConnection object. I would always be thinking “whats the difference between these seemingly identical methods??” Even worse, if you add some custom code inside the UsersWrapper Search method, you cannot always guarentee that it will be called. The possibility will always exist for a developer to call Search directly without going through the UsersWrapper.

    Fowler in his book PoEAA defines a pattern called Gateway. This is a way to simplify and customize the interface to an external system or library.

    public class AD
    {
        private LdapConnection ldapConn;
        private UsersWrapper users;
    
        public AD()
        {
            this.ldapConn = new LdapConnection(new Settings(/* configure settings here*/));
            this.users = new UsersWrapper(this.ldapConn);
        }
    
        public UsersWrapper Users
        {
            get
            {
                return this.users;
            }
        }
    
        public class UsersWrapper
        {
            private LdapConnection ldapConn;
    
            public UsersWrapper(LdapConnection ldapConn)
            {
                this.ldapConn = ldapConn;
            }
    
            public object Search()
            {
                return this.ldapConn.Search();
            }
    
            public void Add(object something)
            {
                this.ldapConn.Add(something);
            }
    
            public void Delete(object something)
            {
                this.ldapConn.Delete(something);
            }
        }
    }
    

    This can then be used like so:

    AD myAD = new AD();
    object results = myAD.Users.Search();
    

    Here you can see that the LdapConnection object is completly encapsulated inside the class and there is only one way to call each method. Even better, the setting up of the LdapConnection is also completely encapsulated. The code using this class doesn’t have to worry about how to set it up. The settings are only defined in one place (in this class, instead of spread throughout your application).

    The only disadvantage is that you loose the inheritance chain back to LdapConnection, but I dont think this is necessary in your case.

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

Sidebar

Related Questions

I have a third party library that internally constructs and uses the SqlConnection class.
I have a third-party library in my SVN repository and I'd like to associate
Say I have a third party Application that does background work, but prints out
I have some third party library Foo with class FooBar . I think that
I have a third party library that I'm attempting to incorporate into a simulation.
I have a third-party app that creates HTML-based reports that I need to display.
I have a third party .NET Assembly and a large Java application. I need
I have an third-party applet that requires JRE v1.5_12 to work correctly. THe user
I have a third-party product, a terminal emulator, which provides a DLL that can
I have a third-party ActiveX dll, and I'd like to register it programmatically at

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.