Print Page | Close Window

DataSourceKeyMap is too persistent

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=3105
Printed Date: 22-May-2025 at 10:10pm


Topic: DataSourceKeyMap is too persistent
Posted By: MVenhola
Subject: DataSourceKeyMap is too persistent
Date Posted: 22-Nov-2011 at 7:55am
The DataSourceKeyMap dictionary in the DataSourceResolver object is a static property!  This is causing some real headaches. 
We've implemented a custom login screen with a server selection option.  After logging in our KeyResolver picks up our keys based on the server selection.
 
User logs out and the forms authentication login screen comes up as expected.
 
User logs in again, selecting a different server.  However, because the DataSourceKeyMap is static (and apparently, not clearable... we tried EntityManager.DataSourceResolver.DataSourceKeyMap.Clear(), didn't work), the only way the keys are reset is by closing the browser (ie, shutting down the app).
 
Shouldn't there be a way to reset the keys?



Replies:
Posted By: DenisK
Date Posted: 22-Nov-2011 at 5:35pm
Hi MVenhola;

Currently, there isn't a way to reset the keys.

However, your use case seems like a perfect example to use DataSourceExtension. Basically you pass in your DataSourceExtension when you create your EntityManager, and in your IDataSourceKeyResolver.GetKey method, you just resolve different keys based on the extension passed in.

See  http://drc.ideablade.com/xwiki/bin/view/Documentation/data-sources#HDynamicconnectionstrings - http://drc.ideablade.com/xwiki/bin/view/Documentation/data-sources#HDynamicconnectionstrings  for more details.

Hope this helps.


Posted By: MVenhola
Date Posted: 23-Nov-2011 at 6:55am
But it doesn't help.
 
The environment is selected on the server side during the login process.  Silverlight app is initialized after this.  The extension key wouldn't be known when the EntityManager is created on the client side.  It's a catch 22.
 
Hence the need to be able to clear the map.


Posted By: MVenhola
Date Posted: 23-Nov-2011 at 7:11am
Nevermind. Solution was simple.
When creating the entity manager on the client side, I pass a Guid.NewGuid().ToString("N") as the extension key, forcing each silverlight app to have it's own key values in the map.
 
Works as expected now.


Posted By: kimj
Date Posted: 23-Nov-2011 at 9:55am
When you use a dynamic key extension like this you'll effectively have one EntityServer per Silverlight client, which in the long run is probably not what you want.  DevForce will create one EntityServer per key extension, but this usually translates into many clients with that key extension communicating with the one EntityServer dedicated to them. 
 
Since your login process is not part of the Silverlight application, you might be able to use initParams to pass the server information to the SL application, which in turn would use this as its key extension when creating an EntityManager. 
 
If initParams won't work, then maybe use one extension-less EntityManager to ask (maybe via an RPC call) which server it should be using for the user, and then create an EntityManager with a key extension representing that server.



Print Page | Close Window