-
-
Notifications
You must be signed in to change notification settings - Fork 23
Fix AddDispatchR when dispatchR and handlers are in same project and … #23
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,9 +36,7 @@ public IAsyncEnumerable<TResponse> CreateStream<TRequest, TResponse>(IStreamRequ | |
|
||
public async ValueTask Publish<TNotification>(TNotification request, CancellationToken cancellationToken) where TNotification : INotification | ||
{ | ||
var notificationsInDi = serviceProvider.GetRequiredService<IEnumerable<INotificationHandler<TNotification>>>(); | ||
|
||
var notifications = Unsafe.As<INotificationHandler<TNotification>[]>(notificationsInDi); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bro, this piece of code is necessary because when you use foreach on an IEnumerable, it causes boxing, which leads to memory allocation on the heap. With this approach, we avoid using foreach directly on IEnumerable. More information: https://youtu.be/7w4ho3WzKss?list=PLGiSgN3ODieILgFQN1puu-ey9guWwnxGX&t=3280 |
||
var notifications = serviceProvider.GetRequiredService<IEnumerable<INotificationHandler<TNotification>>>(); | ||
foreach (var notification in notifications) | ||
{ | ||
var valueTask = notification.Handle(request, cancellationToken); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great, but I feel like we’ve drifted away from the original goal. We wanted to avoid picking up interfaces, but now we’re explicitly saying it has to be a class and not abstract.
I think if we just exclude interfaces and allow everything else, we could also support other types like structs.
What do you think?