Skip to content

Instantly share code, notes, and snippets.

@jchannon
Last active December 1, 2015 16:31
Show Gist options
  • Save jchannon/e97e8f1d4534c9f67018 to your computer and use it in GitHub Desktop.
Save jchannon/e97e8f1d4534c9f67018 to your computer and use it in GitHub Desktop.
protected override void ConfigureApplicationContainer(TinyIoCContainer container)
{
//base.ConfigureApplicationContainer(container); //Prevent assembly scanning
container.Register<IDbConnectionProvider, PostgresConnectionProvider>();
}
public interface IDbConnectionProvider
{
IDbConnection GetConnection();
}
public class PostgresConnectionProvider : IDbConnectionProvider
{
private readonly string connectionString;
public PostgresConnectionProvider()
{
this.connectionString = ConfigurationManager.ConnectionStrings["blah"].ConnectionString;
}
public IDbConnection GetConnection()
{
var connection = new NpgsqlConnection(this.connectionString);
connection.Open();
return connection;
}
}
public UserRepository(IDbConnectionProvider dbConnectionProvider)
{
this.dbConnectionProvider = dbConnectionProvider;
}
public VQUser GetVQuser(int id)
{
using (var dbConnection = this.dbConnectionProvider.GetConnection())
{
return dbConnection.Query<User>(
UserSql + " where u.id = @id",
new { id = id }).FirstOrDefault();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment