Basic Connection Factory
The LdapConnectionFactory class is a basic factory that allows you to configure the creation of connections and create them. It will create a connection on demand and dispose any connection passed to ReleaseConnection. It is stand alone or one can be configured on
LDAP Configuration.
// standalone
var connectionFactory = new ConnectionFactory("server:389");
connectionFactory
.AuthenticateAs(CredentialCache.DefaultNetworkCredentials);
var connection = connectionFactory.GetConnection();
connectionFactory.ReleaseConnection(connection);
// via LdapConfiguration
ldapConfiguration.ConfigureFactory("server:389")
.AuthenticateAs(CredentialCache.DefaultNetworkCredentials);
var connection = ldapConfiguration.ConnectionFactory.GetConnection();
ldapConfiguration.ConnectionFactory.ReleaseConnection(connection);
Pooled Connection Factory
This connection factory can only be configured from the
LDAP Configuration. The initial authentication bind is often the most expensive part of performing a query. Using a connection pool can reuse connections that have already been authenticated. This can be useful in environments that need to perform a large number of queries from different clients.
ldapConfiguration.ConfigurePooledFactory("server:389")
.MinPoolSizeIs(1)
.MaxPoolSizeIs(50)
.AuthenticateAs(new NetworkCredential("account", "password"));
Custom Factories
LDAP Configuration will allow you to associate a custom connection factory that implements ILdapConnectionFactory. The ConnectionFactoryBase class can simplify the process.