DevForce Help Reference
IDataSourceKeyResolver Interface
Members  Example 


Interface used to resolve the data source key which will be used to connect to a data source.
Syntax
'Declaration
 
<InterfaceExportAttribute(ContractName="", ContractType=IdeaBlade.EntityModel.IDataSourceKeyResolver)>
Public Interface IDataSourceKeyResolver 
'Usage
 
Dim instance As IDataSourceKeyResolver
[InterfaceExport(ContractName="", ContractType=IdeaBlade.EntityModel.IDataSourceKeyResolver)]
public interface IDataSourceKeyResolver 
Remarks
The DefaultDataSourceKeyResolver is used by default to determine the key and connection information to be used when accessing a data source. To override this behavior implement a custom IDataSourceKeyResolver. If a custom IDataSourceKeyResolver is found, a single instance of the class will be created for the EntityManager and called for all data source key resolution.

If using a custom IDataSourceKeyResolver you will not need to place data source key information in your IdeaBlade Configuration file.

Example
// Sample custom implementation of IDataSourceKeyResolver.

[Serializable]
public class DynamicDataSourceKeyResolver : IDataSourceKeyResolver {

  // This class will generate a new key when the extension of "Dynamic" is used.  
  // All other keys are handled by the default resolver.
  // Note the edmKey created here is not defined in the IdeaBlade configuration file.

  // Also note that GetKey will be called once on both the client and the server.

  public IDataSourceKey GetKey(String keyName, String keyExtension, bool onServer) {

    // Generally no need for customization on client, so allow default resolution.
    if (!onServer) return null;

    if (keyExtension != "Dynamic") return null;  // Allow default resolution of key.

    // We've already defined <connectionStrings> in our config file, so see what's there.
    var cs = IdeaBladeConfig.Instance.Configuration.ConnectionStrings.ConnectionStrings[keyName];

    // Switch database server based on time of day.
    string connection = cs.ConnectionString;
    if (DateTime.UtcNow.Hour > 12) {
      connection = connection.Replace("Data Source=SF-Server", "Data Source=NY-Server");
    } 

    ClientEdmKey newKey = new ClientEdmKey("mynewkey", connection);
    return newKey;
  }
}
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

IDataSourceKeyResolver Members
IdeaBlade.EntityModel Namespace

Send Feedback