The lifetime is a parameter on AddDbContext<>()
. See example:
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")),
ServiceLifetime.Transient);
This will add it to the service collection with transient lifetime.
More Related Contents:
- Dynamically change connection string in Asp.Net Core
- Dynamically access table in EF Core 2.0
- How to mock an async repository with Entity Framework Core
- .Net Core 3.0 possible object cycle was detected which is not supported
- .NET Core 2.1 Identity get all users with their associated roles
- Cannot access a disposed object in ASP.NET Core when injecting DbContext
- How to instantiate a DbContext in EF Core
- Command dotnet ef not found
- Unable to create migrations after upgrading to ASP.NET Core 2.0
- Dynamically changing schema in Entity Framework Core
- How to unapply a migration in ASP.NET Core with EF Core
- EF CORE 2.1 HasConversion on all properties of type datetime
- Is there an Entity Framework 7 Database-First POCO Generator?
- How to make EF-Core use a Guid instead of String for its ID/Primary key
- loading a full hierarchy from a self referencing table with EntityFramework.Core
- In-memory database doesn’t save data
- Avoid or control circular references in Entity Framework Core
- Unable to edit db entries using EFCore, EntityState.Modified: “Database operation expected to affect 1 row(s) but actually affected 0 row(s).”
- Add migration with different assembly
- ASP – Core Migrate EF Core SQL DB on Startup
- Entity Framework Core: `SqlNullValueException: Data is Null.` How to troubleshoot?
- How to load navigation properties on an IdentityUser with UserManager
- How to get user information in DbContext using Net Core
- How should I manage DbContext Lifetime in MVC Core?
- Implementing recursive property loading in EF Core
- How to resolve .net core build error NETDSDK1061 and warning MSB3277
- Update-Database command is not working in ASP.Net Core / Entity Framework Core because object in database already exists
- How do you create a custom AuthorizeAttribute in ASP.NET Core?
- Enable OPTIONS header for CORS on .NET Core Web API
- Could not load file or assembly Microsoft.Extensions.DependencyInjection.Abstractions, Version=1.1.0.0