Static Factory

Oct 11, 2011 at 4:33 PM

Hi,

 

I'm trying to use LINQ to LDAP at a synch service, but I'm facing issues with the static Connection Factory.

In my case, it was enough to add a backing field to the LdapConnectionFactory property in the LdapConfiguration class and mark it as ThreadStatic.

Do you see any problems with this workaround?

 

Thanks!

Oct 11, 2011 at 9:40 PM

I also had to mark the Mappings attribute in the DirectoryMapper as ThreadStatic.

Coordinator
Oct 31, 2011 at 1:08 AM

Hi marlongaspar,

Can you tell me which version you're using?  The ConnectionFactory is meant to be write once read many.  Are you initializing it more than once?  Also, the DirectoryMapper uses a ConcurrentDictionary internally in version 2.0 so ThreadStatic is not necessary there.  

The only downside that I can see to using ThreadStatic is you will have a ConnctionFactory and Dictionary of mappings per thread.  For the standard ConnectionFactory that shouldn't be a big deal, but for the PooledConnectionFactory (depending on your configuration) could spin up quite a few unnecessary connections.  I believe most LDAP Servers have a connection limit that you could potentially run into.