How to install a custom DriverConnectionProvider with Fluent NHibernate

How to install custom DriverConnectionProvider with Fluent NHibernate?

Sincerely, Alexey Zakharov

+3
source share
1 answer

I find a solution. Here is a small example of how this can be done.

Fluently.Configure()
    .Database(MsSqlConfiguration.MsSql2008
                    .ConnectionString(".......")
                    .ShowSql()
                    .Provider<TenantConnectionProvider>()
                    )

public class TenantConnectionProvider : DriverConnectionProvider
{
    public override IDbConnection GetConnection()
    {
        IDbConnection conn = Driver.CreateConnection();
        try
        {
            conn.ConnectionString = // Tenant connection string provider called here
            conn.Open();
        }
        catch (Exception)
        {
            conn.Dispose();
            throw;
        }

        return conn;


   }
}
+12
source

Source: https://habr.com/ru/post/1747512/


All Articles