Skip to content

Add service retrieval by ID  #317

@charphi

Description

@charphi

Add retrieval by ID when a service has a ServiceId annotation.

Example:

@ServiceDefinition(quantifier = Quantifier.MULTIPLE, batch = true)
public interface HashAlgorithm {

    @ServiceId(pattern = ServiceId.SCREAMING_KEBAB_CASE)
    String getName();

    String hashToHex(byte[] input);

    static void main(String[] args) {
        // current code
        HashAlgorithmLoader
                .load()
                .stream()
                .filter(algo -> algo.getName().equals("SHA-256"))
                .findFirst()
                .ifPresent(algo -> System.out.println(algo.hashToHex("hello".getBytes(UTF_8))));

        // initial retrieval code
        new HashAlgorithmLoader()
                .getById("SHA-256")
                .ifPresent(algo -> System.out.println(algo.hashToHex("hello".getBytes(UTF_8))));

        // additional retrieval code
        HashAlgorithmLoader
                .loadById("SHA-256")
                .ifPresent(algo -> System.out.println(algo.hashToHex("hello".getBytes(UTF_8))));
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions