appccelerate / statemachine

A .net library that lets you build state machines (hierarchical, async with fluent definition syntax and reporting capabilities).
Apache License 2.0
488 stars 128 forks source link

Question: how to log internal changes #84

Closed LiorBanai closed 1 year ago

LiorBanai commented 1 year ago

Hi, I found this library and it seems great to my needs. I was wondering how than I log changes (events triggering, current state, etc), can I pass Ilogger for example? also how to write unit test that access the internal state after event was fired to verify the correct changes.

ursenzler commented 1 year ago

Hi! Yes, you can pass an IExtension (https://github.com/appccelerate/statemachine/blob/6ae943467fca0472887aefeeeb9d387cb17354f4/source/Appccelerate.StateMachine/ActiveStateMachine.cs#L287). You can derive from ExtensionBase so that you don't have to implement all callback methods: https://github.com/appccelerate/statemachine/blob/6ae943467fca0472887aefeeeb9d387cb17354f4/source/Appccelerate.StateMachine/Extensions/ExtensionBase.cs#L33

For unit tests, you can use something like I did here: https://github.com/appccelerate/statemachine/blob/6ae943467fca0472887aefeeeb9d387cb17354f4/source/Appccelerate.StateMachine.Specs/Sync/CurrentStateExtension.cs#L24

A word of caution: I'm not actively working on this code at the moment. So if you need to run it on another target, the best way is to fork the repo and change the target yourself. But if you need help, feel free to ask.

LiorBanai commented 1 year ago

@ursenzler thanks!

LiorBanai commented 1 year ago

btw, any reason why the license is apache and not mit (which is commonly used I guess)?

ursenzler commented 1 year ago

A decision made many many years ago. Is it a problem for you?

LiorBanai commented 1 year ago

not a problem. Thanks again.