Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PT-12212: Ability to override the DbContextUnitOfWork #2666

Merged
merged 6 commits into from
Jun 27, 2023
Merged

Conversation

OlegoO
Copy link
Contributor

@OlegoO OlegoO commented Jun 15, 2023

Description

Introduces the ability to override the DbContextUnitOfWork for improvements by third-party services.

Sample implementation using the entityframework-extensions.net library:

  1. Create a new vc module
  2. Configure entityframework-extensions.net library
  3. Create DbContextWithBulkSaveChangesUnitOfWork class to extend the DbContextUnitOfWork and overrides the Commit and CommitAsync methods to use bulk save changes for improved performance.
  4. Overrider DbContextUnitOfWork by DbContextWithBulkSaveChangesUnitOfWork in module initialization.
/// Use https://entityframework-extensions.net/tutorial-bulk-savechanges
 public class DbContextWithBulkSaveChangesUnitOfWork : DbContextUnitOfWork
    {
        public DbContextWithBulkSaveChangesUnitOfWork(DbContext context) : base(context)
        {

        }

        public async override Task<int> CommitAsync()
        {
            await base.DbContext.BulkSaveChangesAsync();
            return 1;
        }

        public override int Commit()
        {
            base.DbContext.BulkSaveChanges();
            return 1;
        }
    }
public class Module : IModule, IHasConfiguration
{
 ...
    public void Initialize(IServiceCollection serviceCollection)
    {
        // Override models
        AbstractTypeFactory<DbContextUnitOfWork>.OverrideType<DbContextUnitOfWork, DbContextWithBulkSaveChangesUnitOfWork>();
    }
 ...
}

References

QA-test:

Jira-link:

Artifact URL:

@OlegoO OlegoO requested a review from ksavosteev June 22, 2023 09:38
@OlegoO OlegoO changed the title PT-12212: Extend your DbContext with high-performance batch and bulk operations PT-12212: Ability to override the DbContextUnitOfWork Jun 22, 2023
@sonarcloud
Copy link

sonarcloud bot commented Jun 26, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

16.7% 16.7% Coverage
0.0% 0.0% Duplication

@OlegoO OlegoO merged commit e2beb49 into dev Jun 27, 2023
10 checks passed
@OlegoO OlegoO deleted the feat/PT-12212 branch June 27, 2023 07:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant