Skip to content

Instantly share code, notes, and snippets.

@cbcwebdev
Created March 20, 2012 20:05
Show Gist options
  • Save cbcwebdev/2140744 to your computer and use it in GitHub Desktop.
Save cbcwebdev/2140744 to your computer and use it in GitHub Desktop.
public class ConnectionFactory
{
public static IDbConnection Create()
{
var connection = new SqlConnection(ConfigurationManager.ConnectionStrings["default"].ConnectionString);
connection.Open();
return new ProfiledDbConnection(connection, MiniProfiler.Current);
}
}
protected void Application_BeginRequest()
{
if(IsProfiledRequest)
MiniProfiler.Start(ProfileLevel.Verbose);
}
protected void Application_EndRequest()
{
if(IsProfiledRequest)
MiniProfiler.Stop();
}
protected bool IsProfiledRequest
{
get
{
bool shouldProfile;
Boolean.TryParse(Request["profiler"], out shouldProfile);
return (Request.IsLocal || shouldProfile);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment