Comments (2)
The default EF Core lifetime is Scoped, which has nothing to do with StructureMap (but StructureMap will use this if it's used as the container as in this case). If you want to create separately-scoped instances of DbContext, you can create child scopes as described here:
You might at that point need to pass the dbContext into a new instance of a repo you create yourself, rather than requesting one from the container. Let me know if that helps/makes sense.
from cleanarchitecture.
Sorry it took me so long to get back to this.
I did not manage to solve the issue using your suggestion, but I'll leave here my workaround, in case it can be useful to someone else.
Basically I had a set of events that lead to a loop on 1000+ insertions, and as the dbContextkept everything in memory, it started to get slower and slower...
My solution was to detach all entities from the dbContext after each insertion, as they were not needed anymore.
...
// The event handler that dealt with the 1000+ similar events and thus generated 1000+ inserts
public void HandlePost(MyEntityCreatedEventPost domainEvent)
{
...
_aggregate.Insert(entity); // note: does a dbContext.SaveChanges()
_aggregate.DetachAll();
...
}
// And the cleanup method to keep the dbContext nimble
public void DetachAll()
{
foreach (EntityEntry dbEntityEntry in _dbContext.ChangeTracker.Entries().Where(e => e.Entity != null).ToList())
{
dbEntityEntry.State = EntityState.Detached;
}
}
from cleanarchitecture.
Related Issues (20)
- Update to target latest net8 for Nov 2023 release HOT 1
- Api.Contracts project HOT 2
- Two sets of templates - Back end focused (Current [End Points]) and Front end focused (Blazor Web App) HOT 2
- Template Generated Solution Will not Build or Update HOT 2
- Please support domain event publishing of 'EntityBase<TId>' HOT 3
- Template Doesn't Work and Breaks Other Projects HOT 1
- Open the Discussions area in Github area so people can discuss the template and the whys
- Why is this repo using AutoFac instead of .NET's own DI infrastructure? HOT 3
- Handling Third-Party Authentication and Role Synchronization in DDD and Clean Architecture HOT 1
- GetContributorByIdRequest - Filename should probably match the classname
- Why is the implementation of the DeleteContributorService in the core layer? HOT 2
- Test case ReturnsTwoContributors() fails HOT 6
- Replace Autofac with Vanilla dotnet DI HOT 3
- Renaming Enhacement in Web Project. HOT 3
- Update Sample to Latest Version of Template HOT 4
- 404 when launching the project HOT 2
- Error when launching the newly created project from template HOT 2
- Add More Warning as Error Checks
- Mixed SharedKernel : Clean.Architecture and Ardalis HOT 1
- ProjectItemMarkComplete test fails
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cleanarchitecture.