micronaut-projects / micronaut-core

Micronaut Application Framework
http://micronaut.io
Apache License 2.0
6.09k stars 1.07k forks source link

[Feature] Support for generic events in @EventListener #5281

Open fromlabs opened 3 years ago

fromlabs commented 3 years ago

It would be nice to support:

@EventListener
public void onPersonCreated(EntityCreatedEvent<Person> event) {
    // ...
}

In Spring this is possible implementing ResolvableTypeProvider:

public class EntityCreatedEvent<T> extends ApplicationEvent implements ResolvableTypeProvider {

    public EntityCreatedEvent(T entity) {
        super(entity);
    }

    @Override
    public ResolvableType getResolvableType() {
        return ResolvableType.forClassWithGenerics(getClass(), ResolvableType.forInstance(getSource()));
    }
}

Spring Framework Generic Events

utsav0209 commented 3 years ago

@graemerocher @jameskleeh I have been trying to look into this issue lately, I was wondering if by any chance micronaut preprocessor saves type details for method arguments the way it stores for the classes?

graemerocher commented 3 years ago

possibly, we would need to look into. Probably a Micronaut 3.0 thing as we have better generics support in the 3.0.x branch

utsav0209 commented 3 years ago

@graemerocher, thanks I will have a look in that branch and see if I can come up with something