Closed (fixed)
Project:
Drupal core
Version:
10.6.x-dev
Component:
base system
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
6 Jul 2025 at 16:00 UTC
Updated:
22 Jul 2025 at 08:14 UTC
Jump to comment: Most recent
The keyvalue service cannot be autowired since the Drupal\Core\KeyValueStore\KeyValueFactoryInterface service alias is missing. Same for keyvalue.expirable
Drupal\Core\KeyValueStore\KeyValueFactoryInterface alias to the container.Drupal\Core\KeyValueStore\KeyValueExpirableFactoryInterface alias to the container.Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
znerol commentedComment #4
nicxvan commentedI don't see any reason not to do this, but two things I've seen.
You can still autowire using the attribute and service id.
Usually I see these conversions done in the issue that needs the autowiring.
If this is so contrib can do it a link to that issue would be helpful.
Comment #5
znerol commentedCame here from #3397420: Add a way to capture mails sent through the mailer transport service during tests. Autowiring is not a requirement over there, but I noticed that referencing
KeyValueFactoryInterface::classdid not work. I.e.:Regarding the process, we had a couple of these in the past (e.g., #3529592: Wrong alias for access_policy_processor service in core.services.yml and #3401331: Add Psr\EventDispatcher\EventDispatcherInterface alias to core services).
Comment #6
nicxvan commentedOh are you in a service provider?
I was talking about this
public function __construct(
#[Autowire(service: 'monolog.logger.request')]
private LoggerInterface $logger,
) {
https://symfony.com/doc/current/service_container/autowiring.html
Comment #7
znerol commentedRetitled and made it into a task to match the previous issue.
Comment #8
nicxvan commentedLooks right to me!
Comment #9
larowlanWhen autowiring went in originally, we added
core/tests/Drupal/KernelTests/Core/DependencyInjection/AutowireTest.phpthat is supposed to error if a services is added without a FQCN alias. Can we do some digging to work out why these services weren't causing that test to fail, so we can be sure that test is doing what we expect?Comment #10
nicxvan commentedIs it just new services? I swear I have had to add them too.
Comment #11
znerol commentedcore.services.ymlcontains the followingkeyvaluerelated definitions:The services
keyvalueandkeyvalue.databaseboth implementKeyValueFactoryInterface. Likewise the serviceskeyvalue.expirableandkeyvalue.expirable.databaseboth implementKeyValueExpirableFactoryInterface. TheAutowireTestonly requires an alias for classes that are the only implementations of an interface.Comment #12
larowlanThanks for explaining!
Comment #13
longwaveI deliberately did not add this at the time we added the rest of the aliases because of the possible confusion between
keyvalueandkeyvalue.databaseas they share the interface, but you will (almost) always wantkeyvalueto proxy to the selected implementation so adding the alias to that makes sense so it can be injected more easily. And exactly the same applies for the expirable services too.Comment #16
catchThanks for #11 and #13 (and #9 which prompted the answers), this makes loads of sense with those explanations but a bit hard to get my head around otherwise.
Committed/pushed to 11.x, thanks! I think we want this in 10.6.x too so that contrib can use autowiring by requiring >= 10.6 | >= 11.3, so cherry-picked there too.