Closed
Description
Description
The step-by-step guide at https://json-api-dotnet.github.io/JsonApiDotNetCore/getting-started/step-by-step.html instructs to add the following code to Startup.ConfigureServices:
public IServiceProvider ConfigureServices(IServiceCollection services)
{
// add the db context like you normally would
services.AddDbContext<AppDbContext>(options =>
{ // use whatever provider you want, this is just an example
options.UseNpgsql(GetDbConnectionString());
}, ServiceLifetime.Transient);
// add jsonapi dotnet core
services.AddJsonApi<AppDbContext>();
// ...
}
I wonder why ServiceLifetime.Transient
needs to be passed. because it is not in the official EF Core 3 documentation. Official sample at https://github.com/dotnet/AspNetCore.Docs/blob/master/aspnetcore/data/ef-rp/intro/samples/cu30/Startup.cs
Unless the scope setting is required for some reason, I think it would be better to remove it, so the context can be reused within a single request.
See also: https://stackoverflow.com/questions/37507691/entity-framework-core-service-default-lifetime.