Пакет услуг включает MiniProfiler на собственное соединение с БД

В документации Mini Profiler вы можете сделать следующее:

public static DbConnection GetOpenConnection()
{
    var cnn = CreateRealConnection(); // A SqlConnection, SqliteConnection   ... or whatever

    // wrap the connection with a profiling connection that tracks timings 
    return new StackExchange.Profiling.Data.ProfiledDbConnection(cnn,     MiniProfiler.Current);
}

Как мне включить профилированное соединение БД в Servicestack с использованием версии Servicestack реализации Miniprofiler для моего собственного соединения с БД. У меня есть функция, которая возвращает строку подключения вместо использования встроенного в базу сервиса.

public static DbConnection GetOpenConnection(string ConnectionName)
    {
        string provider = ConfigurationManager.ConnectionStrings[ConnectionName].ProviderName;
        string connectionstring = ConfigurationManager.ConnectionStrings[ConnectionName].ConnectionString;

        DbProviderFactory factory = DbProviderFactories.GetFactory(provider);
        DbConnection cnn = factory.CreateConnection();
        cnn.ConnectionString = connectionstring;
        cnn.Open();
        //this is ServiceStack current profiler for request and response DTO's
        Profiler profiler = Profiler.Current;
        // I want to return a profiled db connection here that will include the connection profiles into the current Profiler data.
        return cnn;

    }

1 ответ

Решение

Вы сделали бы то же самое, что и Ormlite, и просто обернули свое соединение с MiniProfiler ProfiledDbConnectionНапример:

return new ProfiledDbConnection(cnn, Profiler.Current)
Другие вопросы по тегам