Skip to content

Remove parameter name usage for AutowireDatabase #13

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

Merged
merged 3 commits into from
Dec 9, 2023

Conversation

alcaeus
Copy link
Collaborator

@alcaeus alcaeus commented Dec 8, 2023

As it is, there is no way to autowire the default database without explicitly specifying the name, instead it will always use the parameter name. To work around this, we remove usage of the parameter name and fall back to the default database; not specifying a default_database option or the database parameter in the AutowireDatabase attribute will result in an exception. We could use some magic to fall back to the parameter name if no default database was set, but I don't believe that results an improvement and only makes for more confusing rules.

@alcaeus alcaeus requested a review from GromNaN December 8, 2023 14:41
@alcaeus alcaeus self-assigned this Dec 8, 2023
Copy link
Contributor

@OskarStark OskarStark left a comment

Choose a reason for hiding this comment

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

Please adjust the README examples

@alcaeus alcaeus mentioned this pull request Dec 9, 2023
@alcaeus alcaeus requested a review from OskarStark December 9, 2023 08:33
Copy link
Collaborator

@GromNaN GromNaN left a comment

Choose a reason for hiding this comment

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

I don't get the issue.

@@ -48,7 +48,7 @@ static function (Database $mydb): void {

$this->assertSame(Database::class, $definition->getClass());
$this->assertEquals($autowire->value, $definition->getFactory());
$this->assertSame('mydb', $definition->getArgument(0));
$this->assertSame('%MongoDB\Client.default_database%', $definition->getArgument(0));
Copy link
Collaborator

Choose a reason for hiding this comment

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

That's an ugly parameter name. Can we find something more conventional?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That's an ugly parameter name. Can we find something more conventional?

I'll address that in a separate PR - maybe we can always use <clientId>.default_database

@alcaeus alcaeus force-pushed the remove-database-autonaming branch from 1a6f95f to 2a2550c Compare December 9, 2023 08:48
@alcaeus
Copy link
Collaborator Author

alcaeus commented Dec 9, 2023

I don't get the issue.

Before this PR, there was no way to inject a Database instance for the default database without specifying the database name. Since the database name may change between environments (as it did in my case), this is not a very good option.

@alcaeus alcaeus requested a review from GromNaN December 9, 2023 11:26
@alcaeus alcaeus merged commit 2d3784a into mongodb-labs:0.2 Dec 9, 2023
@alcaeus alcaeus deleted the remove-database-autonaming branch December 9, 2023 11:51
@alcaeus alcaeus added this to the 0.2 milestone Dec 9, 2023
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.

3 participants