var graph = new BehaviorGraph(); graph.BehaviorFor(i => i == 1).Use(() => Console.WriteLine("Input is 1")); graph.BehaviorFor (i => i == 2).Use(() => Console.WriteLine("Input is 2")); graph.Execute(1); // Output: Input is 1 graph.Execute(2); // Output: Input is 2 graph.Execute(3); // No output
var bus = new InMemoryBus(); var handler = new MyEventHandler(); var graph = new BehaviorGraph(); graph.BehaviorForIn the above example, we use BehaviorFor to define a behavior for a specific event type. We then subscribe this behavior to an event bus using the InMemoryBus package. Finally, when an instance of the event is raised on the bus, the corresponding behavior is executed, which in this example is a method on a handler class. This can be useful for event-driven systems where specific behaviors need to be executed based on the type of event raised. The package library used in these examples is the BehaviorGraph package.().Use(() => handler.Handle); bus.Subscribe(graph); bus.Raise(new MyEvent()); public class MyEvent {} public class MyEventHandler { public void Handle(MyEvent @event) { Console.WriteLine("Handling event"); } }