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

Support for inheritance in Command and Notification Handling #24

Closed
1 task done
osoykan opened this issue Sep 22, 2022 · 1 comment
Closed
1 task done

Support for inheritance in Command and Notification Handling #24

osoykan opened this issue Sep 22, 2022 · 1 comment
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@osoykan
Copy link
Collaborator

osoykan commented Sep 22, 2022

Description

Currently, kediatR does not support inherited command and notification handling. But, inheritance is sometimes needed to unify repetitive handler logic into the base class.

class MyCommandForInheritance : Command

abstract class MyAsyncCommandHandlerFor<TCommand : Command> : AsyncCommandHandler<TCommand>

class MyInheritedAsyncCommandHandler : MyAsyncCommandHandlerFor<MyCommandForInheritance>() {
    override suspend fun handleAsync(command: MyCommandForInheritance) {
        // should be invoked but was not registered at all
    }
}

As this example shows, MyInheritedAsyncCommandHandleris not accessible and not registered to the Registry because asyncCommandMap does not consider superClasses while building the container.

Implementation

In the RegistryImpl.kt the collection is being iterated over only the interfaces.

(it.genericInterfaces).forEach { genericInterface ->
if ((genericInterface is ParameterizedType) && genericInterface.rawType as Class<*> == AsyncCommandHandler::class.java) {
val commandClazz = extractCommandClass<Command>(genericInterface)
asyncCommandMap[commandClazz] = AsyncCommandProvider(dependencyProvider, it)

The fix should be located here.

Also, consider:

  • Lift the common registry logic with PartialFunction
@osoykan osoykan added the enhancement New feature or request label Sep 22, 2022
@osoykan osoykan self-assigned this Sep 22, 2022
@osoykan osoykan added this to the 1.1.0 milestone Sep 22, 2022
osoykan added a commit that referenced this issue Sep 23, 2022
osoykan added a commit that referenced this issue Sep 26, 2022
osoykan added a commit that referenced this issue Sep 26, 2022
osoykan added a commit that referenced this issue Sep 26, 2022
@osoykan
Copy link
Collaborator Author

osoykan commented Sep 26, 2022

closed with #27

@osoykan osoykan closed this as completed Sep 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant