In a test project I have the following layers: Web API <-> Service (with DbContext).
I do not use the repository pattern because DbSet
is already a repository.
public class MyService : DbContext
{
public MyService(DbContextOptions<MyDbContext> options)
: base(options)
{
}
...
}
I'm wondering if I should inject the DbContext
for each service, or create the DbContext
within a using statement per method?
DoSomething()
{
using (var db = new DbContext())
{
...
}
}
The advantage of the latter would be that I can run different queries in parallel (I have the case, and at the moment three queries are running sequentially).
Or can I even combine both cases?