11 Replies
I'm just trying to have objects outside of the class fire events, but C# only allows invocations from inside of the declaring class
this is the best way I know of to fire events inside another class
however i'd question if you actually want events if you need to do this
consider having public
Action<>
, Func<>
, or straight delegate
s instead
or, use the mediator pattern to take it to another level of abstractness
the mediatr nuget package is highly-regardedDo actions and funcs have subscribers like events?
I read about some design pattern that isn’t well known called CORE, stands for context objects requests events
Everything is a module called upon through requests and events
CORE design pattern — the way out from overly complicated code | Ha...
Have you ever found yourself stuck in the crazy amount of overly complicated code? No? But you know what it is, right? So let’s suppose you are a developer (at any level of evolution) or you are anyhow involved in product development, then this article is for you! Why? Let’s see the short answer, and then you’re welcome to read more about the so...
So if code wants something done, it makes a request in a context and the module receiving those requests does that and makes an event with the results
events are identical to actions/funcs under the hood
the 'subscriber' to an event is just a method added to the underlying delegate's invocation list
so you can do
I can make that work
Thank you for that
i would suggest looking into mediatr, though
it seems more like what you are after
I will look into everything you’ve told me about, I figured they were just like they were in Java and seemed unfit
So I tested out Actions and Funcs today, neat stuff and created a bucket sort algorithm using a key extractor function
But I have an issue with actions
I have this bit of code that I used to test subscribing methods to the invocation
So it prints 1 2 and 3 just fine
But when I subscribe something else to the action, it is not run when the action is invoked
I did it through another class to see if it's just like events, where you can only subscribe from inside of the declaring class