question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Publish overload with notification of type object

See original GitHub issue

The IMediator interface contains the following method:

Task Publish(object notification, CancellationToken cancellationToken = default);

In its implementation Mediator there is however a runtime type check if the argument notification implements INotification. Why does the interface allow object if callers are supposed to only pass instances which implement INotification?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
lilasquaredcommented, Jun 6, 2019

If at compile time you can’t confirm that your object is of type INotification then you wouldn’t be able to use publish. Without the constraint you can

0reactions
oliverhanappicommented, Aug 19, 2019

Is there any reason why I should not use one of the following?

if (message is INotification notification)
  await _mediator.Publish(notification);

or

await _mediator.Publish((INotification) message);
Read more comments on GitHub >

github_iconTop Results From Across the Web

Overloading a method which accepts `object` as default ...
I need to be able to call a method and pass in an object of an unknown type but then have the correct...
Read more >
Object Overloading - XPN InfoSec Blog
The first thing to notice here that the C: object is actually referencing \Device\HarddiskVolume3 (the actual volume may vary on your system).
Read more >
Publish and subscribe to messages - .NET MAUI
In this example, the Subscribe method subscribes the this object to Hi messages that are sent by the MainPage type, and executes a...
Read more >
Deprecation of '==' operator overload and fake null for ...
Specifically using the `Option` type with a public accessor results in some undesired behavior (Some(null) instead of None). I do see the point ......
Read more >
Incremental overload resolution in object-oriented ...
In this paper, we focus on static overloading in Featherweight Java, which is resolved at compile time based on the types of the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found