Skip to content
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

Remove deprecated code and Factory in favor of full DI #115

Open
damienalexandre opened this issue Oct 4, 2022 · 7 comments
Open

Remove deprecated code and Factory in favor of full DI #115

damienalexandre opened this issue Oct 4, 2022 · 7 comments
Labels
enhancement New feature or request Hacktoberfest v2.0 Breaking Change / Feature planned for 2.0

Comments

@damienalexandre
Copy link
Member

damienalexandre commented Oct 4, 2022

Dependency Injection should be the only way to deal with all our services.

For 2.0, let's get rid of all the error prone code and have only one way to use the lib - removing the Factory.

@damienalexandre damienalexandre added enhancement New feature or request Hacktoberfest v2.0 Breaking Change / Feature planned for 2.0 labels Oct 4, 2022
@VincentLanglet
Copy link
Contributor

Currently the factory allows to override multiple things with these options:

    public const CONFIG_BULK_SIZE = 'elastically_bulk_size';
    public const CONFIG_DENORMALIZER = 'elastically_denormalizer';
    public const CONFIG_INDEX_CLASS_MAPPING = 'elastically_index_class_mapping';
    public const CONFIG_INDEX_NAME_MAPPER = 'elastically_index_name_mapper';
    public const CONFIG_INDEX_PREFIX = 'elastically_index_prefix';
    public const CONFIG_MAPPINGS_DIRECTORY = 'elastically_mappings_directory';
    public const CONFIG_MAPPINGS_PROVIDER = 'elastically_mappings_provider';
    public const CONFIG_SERIALIZER = 'elastically_serializer';
    public const CONFIG_SERIALIZER_CONTEXT_BUILDER = 'elastically_serializer_context_builder';
    public const CONFIG_SERIALIZER_CONTEXT_PER_CLASS = 'elastically_serializer_context_per_class';

Am I wrong or some of them cannot be by the elastically configuration so far ?
I only see config for:

bulk_size
index_class_mapping
prefix
mapping_directory
mapping_provider_service
serializer. context_builder_service
serializer. context_mapping

So we're missing:

denormalizer
index_name_mapper
serializer

https://github.com/jolicode/elastically/blob/master/src/Bridge/Symfony/DependencyInjection/Configuration.php#L69

@damienalexandre
Copy link
Member Author

I think you are right 👍

@lyrixx
Copy link
Member

lyrixx commented Feb 17, 2023

I don't think we need an open issue for such things.

Instead, let's do like Symfony: We keep an UPGRADE.md file up to date to track all deprecation. Then when the 2.x branch is created, we drop everything.

@VincentLanglet
Copy link
Contributor

VincentLanglet commented Feb 17, 2023

I don't think we need an open issue for such things.

Instead, let's do like Symfony: We keep an UPGRADE.md file up to date to track all deprecation. Then when the 2.x branch is created, we drop everything.

I may be wrong but to me this issue is more than just "Remove deprecated code", it's "Let's deprecate the Factory".

  1. Currently the factory class is not deprecated.
  2. As explained by my previous message, currently the factory class cannot be deprecated since everything is not allowed by the config.

So the step to resolve this issue would be:

  • Add a serializer_service option
  • Add a denormalizer_service option
  • Add a index_name_mapper option
  • Do more things...
  • Deprecate the Factory class
  • Close the issue
  • In 2.x, remove the deprecated code

@lyrixx
Copy link
Member

lyrixx commented Feb 17, 2023

@VincentLanglet :

Currently the factory class is not deprecated.

I agree, let's deprecate it completely

As explained by my previous message, currently the factory class cannot be deprecated since everything is not allowed by the config.

We don't need bundle configuration for overriding a service. I'm a bit against adding options to override any part of the lib.

For exemple, the bulk_size, or the mapping_directly are values depending on the application structure / design.

The denormalizer, serializer, index_name_mapper are usually not changed. So we don't need an entry in the configuration to change them.


For example, in Symfony, you don't have an option to change the serializer / router, etc. if you want to do so, you decorate the existing one, or you replace it.

@VincentLanglet
Copy link
Contributor

As explained by my previous message, currently the factory class cannot be deprecated since everything is not allowed by the config.

We don't need bundle configuration for overriding a service. I'm a bit against adding options to override any part of the lib.

For exemple, the bulk_size, or the mapping_directly are values depending on the application structure / design.

The denormalizer, serializer, index_name_mapper are usually not changed. So we don't need an entry in the configuration to change them.

For example, in Symfony, you don't have an option to change the serializer / router, etc. if you want to do so, you decorate the existing one, or you replace it.

Sure, I was expecting such answer.
Maybe I missing some point about services injections/decorations.

The definition of the Indexer is done this way in Elastically:

        ->set('elastically.abstract.indexer', Indexer::class)
            ->abstract()
            ->args([
                '$client' => service(Client::class),
                '$serializer' => service('serializer'),
                '$bulkMaxSize' => abstract_arg('bulk size'),
                '$bulkRequestParams' => [],
                '$contextBuilder' => abstract_arg('elastically.abstract.static_context_builder'),
            ])

If I decorate the serializer

services:
    serializer:
        class: App\NewSerializer

it will override the serializer for the whole application, not just for the elastically services.

What if I only want to change the serializer used by Elastically services ?

@lyrixx
Copy link
Member

lyrixx commented Feb 17, 2023

you need to override the service used in elastically:

service:
    elastically.my_connection.indexer:
        class: App\NewIndexer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Hacktoberfest v2.0 Breaking Change / Feature planned for 2.0
Projects
None yet
Development

No branches or pull requests

3 participants