-
Couldn't load subscription status.
- Fork 36
EF-273: Pure refactoring (no behavior change) moving code out of MongoClientWrapper #252
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors the MongoDB Entity Framework Core provider by moving database creation and index management logic from MongoClientWrapper to MongoDatabaseCreator. This is a pure refactoring that maintains existing behavior while improving the separation of concerns.
Key changes:
- Moved database creation, deletion, and index management methods from
IMongoClientWrapper/MongoClientWrappertoIMongoDatabaseCreator/MongoDatabaseCreator - Updated tests to use
IMongoDatabaseCreatorinstead ofIMongoClientWrapperfor database operations - Simplified
MongoDatabaseFacadeExtensionsby adding a helper method to reduce code duplication
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| MongoDatabaseCreatorTests.cs | New test file with tests moved from MongoClientWrapperTests, updated to use IMongoDatabaseCreator |
| MongoClientWrapperTests.cs | Deleted - tests moved to MongoDatabaseCreatorTests |
| MongoDatabaseCreator.cs | Added database creation, deletion, and index management methods previously in MongoClientWrapper |
| MongoClientWrapper.cs | Removed database/index methods; exposed Client, Database, and DatabaseName as public properties |
| IMongoDatabaseCreator.cs | Added interface methods for database existence checks, index creation, and vector index operations |
| IMongoClientWrapper.cs | Removed database/index method signatures; added Client, Database, and DatabaseName property definitions |
| MongoDatabaseFacadeExtensions.cs | Simplified extension methods using new GetDatabaseCreator helper method |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
src/MongoDB.EntityFrameworkCore/Storage/MongoDatabaseCreator.cs
Outdated
Show resolved
Hide resolved
tests/MongoDB.EntityFrameworkCore.FunctionalTests/Storage/MongoDatabaseCreatorTests.cs
Outdated
Show resolved
Hide resolved
tests/MongoDB.EntityFrameworkCore.FunctionalTests/Storage/MongoDatabaseCreatorTests.cs
Outdated
Show resolved
Hide resolved
tests/MongoDB.EntityFrameworkCore.FunctionalTests/Storage/MongoDatabaseCreatorTests.cs
Outdated
Show resolved
Hide resolved
tests/MongoDB.EntityFrameworkCore.FunctionalTests/Storage/MongoDatabaseCreatorTests.cs
Outdated
Show resolved
Hide resolved
tests/MongoDB.EntityFrameworkCore.FunctionalTests/Storage/MongoDatabaseCreatorTests.cs
Outdated
Show resolved
Hide resolved
tests/MongoDB.EntityFrameworkCore.FunctionalTests/Storage/MongoDatabaseCreatorTests.cs
Show resolved
Hide resolved
b751e43 to
f1fb915
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
src/MongoDB.EntityFrameworkCore/Storage/MongoDatabaseCreator.cs
Outdated
Show resolved
Hide resolved
062ba0d to
ee279c0
Compare
|
@damieng This is now rebased on your transaction changes and ready for review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| IDatabase database) | ||
| : IMongoDatabaseCreator | ||
| { |
Copilot
AI
Oct 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The removal of ICurrentDbContext currentDbContext parameter from the constructor could impact code that depends on this dependency. While the parameter was removed from the constructor signature, consider whether this dependency is needed elsewhere in the class or if there's alternative access to the context when required.
| IDatabase database) | |
| : IMongoDatabaseCreator | |
| { | |
| IDatabase database, | |
| ICurrentDbContext currentDbContext) | |
| : IMongoDatabaseCreator | |
| { | |
| private readonly ICurrentDbContext _currentDbContext = currentDbContext; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is resolved by D.I. and should never be constructed directly.
src/MongoDB.EntityFrameworkCore/Storage/MongoDatabaseCreator.cs
Outdated
Show resolved
Hide resolved
src/MongoDB.EntityFrameworkCore/Storage/MongoDatabaseCreator.cs
Outdated
Show resolved
Hide resolved
| public IMongoClient Client => _client ??= GetOrCreateMongoClient(_options, _serviceProvider); | ||
|
|
||
| /// <inheritdoc /> | ||
| public async Task<IClientSessionHandle> StartSessionAsync(CancellationToken cancellationToken = default) | ||
| => await Client.StartSessionAsync(null, cancellationToken).ConfigureAwait(false); | ||
| public IMongoDatabase Database => _database ??= Client.GetDatabase(_databaseName); |
Copilot
AI
Oct 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changing Client and Database from private to public properties is a breaking change that exposes internal implementation details. Consider the implications of making these publicly accessible, as it may allow consumers to bypass intended abstractions and directly interact with MongoDB primitives.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Documented as internal.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just need to address that copilot note about
Check warning on line 23 in src/MongoDB.EntityFrameworkCore/Metadata/MongoDatabaseCreationOptions.cs
Now referencing the old location for EnsureCreated.
| public interface IMongoClientWrapper | ||
| { | ||
| /// <summary> | ||
| /// The underlying <see cref="IMongoClient"/>. May cause the underlying client to be created. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably want to put the word "Accessing this" before "May"?
| Task<bool> DatabaseExistsAsync(CancellationToken cancellationToken = default); | ||
|
|
||
| /// <summary> | ||
| /// Creates an index in MongoDB based on the EF Core <see cref="IIndex"/> definition. No attempt is made to check that the index |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Should probably be "Create" if the one above is "Determine"? Or "Creates" and "Determines" ?
No description provided.