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

[Feature Request]: Inheritance support in Typed Handler Middleware #508

Open
gschuager opened this issue Jan 11, 2024 · 1 comment
Open
Labels
enhancement New feature or request

Comments

@gschuager
Copy link

Is your request related to a problem you have?

Let's say that we have an inheritance chain as follows:

interface ITaskEvent { }

record TaskStarted : ITaskEvent { }

record TaskStopped : ITaskEvent { }

I'd like to be able to write an implementation of IMessageHandler<ITaskEvent> (not IMessageHandler<TaskStarted> and IMessageHandler<TaskStopped>) to be used with the Typed Handler middleware.

This is currently not supported and since the involved classes are marked as internal, it cannot be customized without duplicating the entire middleware and its related configuration classes.

Describe the solution you'd like

HandlerTypeMapping.GetHandlersTypes can be adjusted to use Type.IsAssignableFrom to match handlers for base types.

Are you able to help bring it to life and contribute with a Pull Request?

Yes

Additional context

No response

@gschuager gschuager added the enhancement New feature or request label Jan 11, 2024
@mhkolk
Copy link

mhkolk commented Feb 2, 2024

There are also issues with using generic Type Resolvers and multiple serializer/deserializer of the same type with different typed handlers. For example, see the following example

This won't work bc the first serializer picks up everything

					.AddDeserializer(f => new KafkaXmlDeserializer(), f => new MarketDocumentTypeResolver<Acknowledgement_MarketDocument>())
						.AddTypedHandlers(handlers => handlers
							.AddHandler<Acknowledgement_MarketDocumentMessageHandler>()
								.WithHandlerLifetime(InstanceLifetime.Scoped)
							.WhenNoHandlerFound(context =>
								Log.Warning("Message not handled > Partition: {0} | Offset: {1} | Context: {2}",
									context.ConsumerContext.Partition,
									context.ConsumerContext.Offset,
									context.ConsumerContext.ToString()))
							)
					.AddDeserializer(f => new KafkaXmlDeserializer(), f => new MarketDocumentTypeResolver<ReserveAllocation_MarketDocument>())
						.AddTypedHandlers(handlers => handlers
							.AddHandler<ReserveAllocation_MarketDocumentMessageHandler>()
								.WithHandlerLifetime(InstanceLifetime.Scoped)
							.WhenNoHandlerFound(context =>
								Log.Warning("Message not handled > Partition: {0} | Offset: {1} | Context: {2}",
									context.ConsumerContext.Partition,
									context.ConsumerContext.Offset,
									context.ConsumerContext.ToString()))
							)

This also won't work bc the typed resolver doesn't match (matches only the first typed handler but not the others that follow)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

No branches or pull requests

2 participants