Skip to content

Conversation

@ajcvickers
Copy link
Collaborator

No description provided.

@ajcvickers ajcvickers requested a review from damieng October 16, 2025 13:34
@ajcvickers ajcvickers requested a review from a team as a code owner October 16, 2025 13:34
Copilot AI review requested due to automatic review settings October 16, 2025 13:34
Copy link
Contributor

Copilot AI left a 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/MongoClientWrapper to IMongoDatabaseCreator/MongoDatabaseCreator
  • Updated tests to use IMongoDatabaseCreator instead of IMongoClientWrapper for database operations
  • Simplified MongoDatabaseFacadeExtensions by 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.

Copy link
Contributor

Copilot AI left a 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.

@ajcvickers
Copy link
Collaborator Author

@damieng This is now rebased on your transaction changes and ready for review.

Copy link
Contributor

Copilot AI left a 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.

Comment on lines +44 to 46
IDatabase database)
: IMongoDatabaseCreator
{
Copy link

Copilot AI Oct 23, 2025

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.

Suggested change
IDatabase database)
: IMongoDatabaseCreator
{
IDatabase database,
ICurrentDbContext currentDbContext)
: IMongoDatabaseCreator
{
private readonly ICurrentDbContext _currentDbContext = currentDbContext;

Copilot uses AI. Check for mistakes.
Copy link
Collaborator Author

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.

Comment on lines +66 to +69
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);
Copy link

Copilot AI Oct 23, 2025

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.

Copilot uses AI. Check for mistakes.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Documented as internal.

ajcvickers and others added 2 commits October 23, 2025 10:28
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Member

@damieng damieng left a 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.
Copy link
Member

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
Copy link
Member

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" ?

@ajcvickers ajcvickers requested a review from damieng October 24, 2025 10:49
@ajcvickers ajcvickers merged commit 73c6b89 into main Oct 24, 2025
16 checks passed
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.

2 participants