问题描述
我目前正在使用NHibernate的项目中为Sql Server实现MSI,为此,我创建了一个自定义DriverDriveProvider。问题是,我现在需要设置访问令牌,并且要获取访问令牌,我需要从配置文件中读取客户端ID。有没有办法将参数传递到自定义的DriverConnectionProvider中?
这就是我所拥有的:
public class MsiConnectionProvider : DriverConnectionProvider
{
public override DbConnection GetConnection(string connectionString)
{
var credential = new DefaultAzureCredential(
new DefaultAzureCredentialOptions
{
ManagedIdentityClientId = "Hard Coded Client Id" //I want to set this using a config variable
});
var tokenReq = new TokenRequestContext(new[] { "Hard Coded Resource Id" }); //I want to set this using a config variable
var accessToken = credential.GetToken(tokenReq);
var conn = (SqlConnection)Driver.CreateConnection();
try
{
conn.AccessToken = accessToken.Token;
conn.ConnectionString = ConnectionString;
conn.Open();
}
catch (Exception)
{
conn.Dispose();
throw;
}
return conn;
}
}
假定自定义DriverDriveProvider设置后会自动调用。因此,我找不到传递这些值的方法。有什么想法吗?
谢谢。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)