Created
January 20, 2012 04:13
-
-
Save NickLarsen/1645114 to your computer and use it in GitHub Desktop.
A connection provider to use with Ninject when using the MvcMiniProfiler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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