C
C#2y ago
Annabelle

❔ Dapper Unit Of Work

So I'm setting up a simple UnitOfWork with dapper For that we need to have a scoped Transaction and Connection
public DapperContext(IConfiguration configuration)
{
var connectionString = configuration.GetConnectionString("DefaultConnectionString");
Connection = new NpgsqlConnection(connectionString);
Connection.Open();
Transaction = Connection.BeginTransaction();
}
public DapperContext(IConfiguration configuration)
{
var connectionString = configuration.GetConnectionString("DefaultConnectionString");
Connection = new NpgsqlConnection(connectionString);
Connection.Open();
Transaction = Connection.BeginTransaction();
}
we register this as
services.AddScoped<IDapperContext, DapperContext>();
services.AddScoped<IDapperContext, DapperContext>();
I have to open connection with Connection.Open(); before creating a transaction though My question is how good of an idea is this? Is there any better way of doing this without blocking?
4 Replies
Annabelle
AnnabelleOP2y ago
Stil interneted
n8ta
n8ta2y ago
What's the problem exactly? Is openning the connection slow such that blocking on it is an issue?
Annabelle
AnnabelleOP2y ago
Yeah Maybe I can do Lazy connection and transaction such that it only opens when actually has to execute Dapper query
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server