如何使用Fluent NHibernate从自定义DriverConnectionProvider读取配置值?

问题描述

我目前正在使用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 (将#修改为@)