Description
IAsyncProfilerProvider
allows to define a custom lifetime for a MiniProfiler
instance but the ProfiledConnection
constructor will inherently reuse the same instance for the lifetime of the connection. If the connection and the IAsyncProfilerProvider
implementations don't have the same matching lifetime then it doesn't work anymore.
For instance, with Sqlite you can reuse the same connection over http requests, so the ProfiledConnection
instance will use the MiniProfiler.Current
of the first request, and all new timings will be ignored for subsequent requests.
Another solution is to just use DefaultOptions.ProfilerProvider
directly from ProfiledConnection
instead of passing a provider, then and use it every time.
Note: I mitigated the issue by implementing a custom profiled connection as explained, with the only caveat that miniProfiler.IsActive
is internal.