Skip to content

Configuration

Alan Hatter edited this page Aug 3, 2020 · 6 revisions

The LdapConfiguration class allows you to configure your class mappings, set the page size for the server (defaults to 500), control the scope of the configuration, disable paging, and configure a default connection factory for DirectoryContext. The configuration should only be done once, but you can have one or more configurations at a time.

Add Mappings

This will forward calls to the Directory Mapper associated with this configuration.

var config = new LdapConfiguration()
    .AddMapping(new AttributeClassMap<Role>())
    .AddMappingsFrom("OtherMappings.dll");

Configure Factory

There are two default factories available for configuration via LdapConfiguration. You can read more about them below. You can also specify a custom factory that implements ILdapConnectionFactory.

config.ConfigureFactory("myserver.com");

config.ConfigurePooledFactory("myserver.com");

config.ConfigureCustomFactory(/**custom factory implmentation**/);

Connection Factories

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 LdapConfiguration.

// 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 LdapConfiguration. 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(0)
     .MaxPoolSizeIs(50)
     .AuthenticateAs(new NetworkCredential("account", "password"));

Custom Factories

You can associate a custom connection factory that implements ILdapConnectionFactory. The ConnectionFactoryBase class can simplify the process.

Clone this wiki locally