Skip to content

Instantly share code, notes, and snippets.

@NickLarsen
Created January 20, 2012 04:13
Show Gist options
  • Save NickLarsen/1645114 to your computer and use it in GitHub Desktop.
Save NickLarsen/1645114 to your computer and use it in GitHub Desktop.
A connection provider to use with Ninject when using the MvcMiniProfiler
// Set your data context to no connection by default and then use this
// bind IDbConnection to this provider. It has to be a provider of
// IDbConnection or else it will try to use the string overload.
//
// Where you register your services, you'll add the following line in your scope of choice:
// kernel.Bind<IDbConnection>().ToProvider<ProfiledDbConnectionProvider>();
internal class ProfiledDbConnectionProvider : Provider<IDbConnection>
{
const string ConnectionStringName = @"connection string name";
protected override IDbConnection CreateInstance(IContext context)
{
var connectionString = ConfigurationManager.ConnectionStrings[ConnectionStringName].ConnectionString;
var connection = new SqlConnection(connectionString);
return new ProfiledDbConnection(connection, MiniProfiler.Current);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment