I recently implemented MiniProfiler into an existing ASP.NET WebForms application that makes use of databinding to the SqlDataSource control. Since the SqlDataSource uses a DbProviderFactory internally, it is fairly simple to exend the control to utilize MiniProfiler through inheritance and overriding a single method of the SqlDataSource.
Here’s a very simple class that inherits from the SqlDataSource control and injects MiniProfiler support to be able to profile the SQL query used by the control:
publicclass ProfiledSqlDataSource : SqlDataSource {protectedoverride DbProviderFactory GetDbProviderFactory() {// get the "base" DbProviderFactory var baseDbProviderFactory = base.GetDbProviderFactory();// Return a ProfiledDbProviderFactory from MiniProfiler// that wraps the "base" DbProviderFactoryreturnnew ProfiledDbProviderFactory( MiniProfiler.Current, baseDbProviderFactory ); } }