Skip to content

[DependencyInjection] Rename "exclude tag" to "resource tag" #60002

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 1 commit into from
Mar 20, 2025

Conversation

kbond
Copy link
Member

@kbond kbond commented Mar 19, 2025

Q A
Branch? 7.3
Bug fix? no
New feature? no
Deprecations? no
Issues Follow up to #59704
License MIT

I find $definition->addExcludedTag('app.model') and $containerBuilder->findExcludedServiceIds('app.model') unintuitive. If feels like your excluding something from the DI container but in fact, your registering it, but in a "different way". The fact that it's an excluded service is just a side-effect. This is especially weird when the tag has attributes ($definition->addExcludedTag('app.model', ['connection' => 'default'])).

Totally open for a name other than "resource".

@carsonbot carsonbot added this to the 7.3 milestone Mar 19, 2025
@carsonbot carsonbot changed the title [DI] Rename "exclude tag" to "resource tag" [DependencyInjection] Rename "exclude tag" to "resource tag" Mar 19, 2025
Copy link
Member

@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.

Resource is more in line with the name we were searching in #59704 (comment)

But in the ContainerBuilder, a resource is already a file or directory path to watch. Isn't there a risk of confusion?

@kbond
Copy link
Member Author

kbond commented Mar 19, 2025

Isn't there a risk of confusion?

Yeah, that is unfortunate... "resource" also makes me think it could be non-classes (js,md,jpg files).

@weaverryan
Copy link
Member

Naming (data model?)

We shouldn't bike shed too much (I'm already ok with this PR and "resource"), but I'd also suggest:

$definition->addDataModelTag('entity', ['connection' => 'default']);

What we know is that the class is not a service: it's a class that holds data: a "data model" class. Maybe it's an entity, maybe a DTO made by the user, or an ApiResource. This "data model" idea seems to cover these cases.

The Container's new Superpower

More generically, it seems like we're adding a new superpower to the container:

  1. it can instantiate services
  2. it can return a list of "data model" classes of some type (e.g. entity)

Is that correct?

@kbond
Copy link
Member Author

kbond commented Mar 19, 2025

addDataClassTag()?

@chalasr
Copy link
Member

chalasr commented Mar 19, 2025

The word Resource is really clever in this context, I think we should not exclude it from the discussion :)
But the fact this removes the explicit exclude from the method name + the possible confusion with resource tracking this would introduce as-is makes me hesitant too.

@chalasr
Copy link
Member

chalasr commented Mar 19, 2025

Not blocking, but I still have the same feeling as in #59704:

Trying to find a generic term for grouping some classes through the container then making them excluded looks like a dead end as there are many possible reasons for a class not to be registered as service and certainly ones we don't even imagine. Excluded services however is a concept we already have

@nicolas-grekas
Copy link
Member

nicolas-grekas commented Mar 19, 2025

I'm for "resource", this is the most generic term. The confusion about config's resources isn't one I would care much about: both things we're talking about are quite advanced concepts that need teaching anyway.

@chalasr
Copy link
Member

chalasr commented Mar 19, 2025

For the remaining point about the excluding behavior being no longer obvious, what about

  • $container->addExcludedResourceTag()
  • Or ->excludeResource($tag)
  • Or ->excludeTaggedResource()?

@nicolas-grekas
Copy link
Member

It's excluded from being a service, but still managed as a resource for invalidating the container.
I think we're safe not having "excluded": this is a service container, not a resource registry, so making something a resource already excludes it from the DIC IMHO, conceptually.

Copy link
Member

@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.

still managed as a resource for invalidating the container.

That convinced me. The definition is a "resource" used during container build.

Copy link
Member

@chalasr chalasr left a comment

Choose a reason for hiding this comment

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

Fair enough 👍

@nicolas-grekas
Copy link
Member

Thank you @kbond.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants