Skip to content

feat: add methods for deleting and removing registered decorators for commands and queries for greater flexibility when managing external dependencies#358

Merged
valdisiljuconoks merged 1 commit intovaldisiljuconoks:masterfrom
mikhail-syvachenko-syzygy:feature/allow-decorator-update-delete
Jul 4, 2025
Merged

feat: add methods for deleting and removing registered decorators for commands and queries for greater flexibility when managing external dependencies#358
valdisiljuconoks merged 1 commit intovaldisiljuconoks:masterfrom
mikhail-syvachenko-syzygy:feature/allow-decorator-update-delete

Conversation

@mikhail-syvachenko-syzygy
Copy link
Contributor

@mikhail-syvachenko-syzygy mikhail-syvachenko-syzygy commented Jun 5, 2025

There are some complications coming from the immutable way decorators are currently registered

The problem was originally spotted in the Optimizely packages, specifically method AddDbLocalizationProvider, class IServiceCollectionExtensions, namespace DbLocalizationProvider.AspNetCore. The registration for decorator happens before the custom configurations were injected, and since there is not a method to remove decorator, now we must use CachedGetAllResourcesHandler, which is underneath using _inner cache, from which I would like to migrate to a custom solution.

Line 47: factory.ForQuery<GetAllResources.Query>().DecorateWith<CachedGetAllResourcesHandler>();
Line 60: setup?.Invoke(ctx);

Obviously, we could solve it in the same file by "swapping" the lines and registering some decorator, which would block registration of CachedGetAllResourcesHandler - but I believe it is much more useful to address the root cause here and create an alternative in case similar problems will be spotted in other places. I added two methods: AddOrReplaceDecorator and RemoveDecorator - which could be handy. They allow to replace existing decorators or clear them completely, if using them is no longer expected.

PR enables replacing externally registered decorators, therefore making the application more extensible and comfortable for developers in the long run.

… commands and queries for greater flexibility when managing external dependencies
@valdisiljuconoks valdisiljuconoks merged commit 52c43a0 into valdisiljuconoks:master Jul 4, 2025
2 of 3 checks passed
@valdisiljuconoks valdisiljuconoks added this to the 8.2.5 milestone Jul 4, 2025
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.

2 participants