MassTransit / Automatonymous

A state machine library for .Net - 100% code - No doodleware
Apache License 2.0
736 stars 117 forks source link

Expose Observers to derived class of AutomatonymousStateMachine #68

Closed kinosang closed 4 years ago

kinosang commented 4 years ago

Make _eventObservers and _stateObservers accessible to derived state mchines.

Or make ConnectEventObserver, ConnectStateObserver accessible to derived state mchines (in constructor).

So that we can connect observers when create a new instance of state mchines.

phatboyg commented 4 years ago

You can call those methods, but I'm not sure why you'd put an observer inside your derived state machine. I'd highly suggest keeping observers separate of the state machine definition.

If you insist on doing it, just cast this to the interface and call it.

kinosang commented 4 years ago

@phatboyg finally, I solve the problem by creating a static factory method.

TLDR;

The reason why I want to put observers inside the state machine is to log all changes on various state machines.

So I just created a base class derived from AutomatonymousStateMachine and want to connect the observer in the constructor.

But I got Cannot access explicit implementation of 'StateMachine<TInstance>.ConnectStateObserver'.

UPDATE

Use this.ConnectStateObserver(observer); instead of ConnectStateObserver(observer); in the constructor.

phatboyg commented 4 years ago

Your case is fairly unique, glad you figured it out.