Bus Lite
1.0.0
Bus-Lite는 이벤트를 사용한 객체 통신을위한 작은 크기의 고성능 도구입니다. 라이브러리는 스레드 안전하고 C#로 작성되었으며 외부 종속성이 없습니다.
2 개의 다른 워크 플로를 지원합니다.
// creating an instance of an event bus
var eventBus = new EventBus ( ) ; // subscribing listener to an event
//
// using Subscribe() we can define multiple listeners for a single event
// listeners can not return any value
//
// first argument is an owner (can not be of type 'ObserverToken')(almost always 'this')
// second argument is a callback function
// method retuns token which is used to unsubscribing (so is owner)
var eventBus = new EventBus ( ) ;
var token = eventBus . Subscribe < string > ( this , ( @event ) => { /* implementation */ } ) ;
var token2 = eventBus . Subscribe ( this , ( string @event ) => { /* implementation */ } ) ;
var token3 = eventBus . Subscribe < string > ( this , new StringEventListener ( ) ) ; // implementation of IEventListener<string>
var token4 = eventBus . Subscribe ( this , new StringEventListener ( ) ) ; // implementation of IEventListener<string> // unsubscribing given listener using it's token
var eventBus = new EventBus ( ) ;
// ...
var token = eventBus . Subscribe < string > ( this , ( @event ) => { /* implementation */ } ) ;
// ...
eventBus . Remove ( token ) ; // unsubscribing all owner's listeners
var eventBus = new EventBus ( ) ;
// ...
eventBus . Subscribe < string > ( this , ( @event ) => { /* implementation */ } ) ;
eventBus . Subscribe < int > ( this , ( @event ) => { /* implementation */ } ) ;
// ...
eventBus . Remove ( this ) ; // pushing event to appropriate listeners
// all required listeners will be notified
var eventBus = new EventBus ( ) ;
// ...
eventBus . Subscribe < string > ( this , ( @event ) => { /* implementation */ } ) ;
eventBus . Subscribe < string > ( this , ( @event ) => { /* implementation */ } ) ;
// ...
eventBus . Notify ( "example string" ) ; //registering handler to an event
//
// using Register() we can define single handler for a single event
// handlers can return value
//
// first argument is an owner (can not be of type 'ObserverToken')(almost always 'this')
// second argument is a callback function
// method retuns token which is used to unsubscribing (so is owner)
var eventBus = new EventBus ( ) ;
var token = eventBus . Register < IEvent < string > , string > ( this , async ( @event ) => await Task . FromResult ( "" ) ) ;
var token2 = eventBus . Register ( this , async ( IEvent < string > @event ) => await Task . FromResult ( "" ) ) ;
var token3 = eventBus . Register < IEvent < string > , string > ( this , new StringEventHandler ( ) ) ; // implementation of IEventHandler<IEvent<string>, string>
var token4 = eventBus . Register ( this , new StringEventHandler ( ) ) ; // implementation of IEventHandler<IEvent<string>, string> // unsubscribing given handler using it's token
var eventBus = new EventBus ( ) ;
// ...
var token = eventBus . Register ( this , new StringEventHandler ( ) ) ;
// ...
eventBus . Remove ( token ) ; // pushing event to appropriate handler
// only one handler will be notified
// call can be awaited and return a value
// if no handler was registed for en event an exception will be thrown
var eventBus = new EventBus ( ) ;
// ...
eventBus . Register ( this , new StringEventHandler ( ) ) ;
// ...
var @event = new StringEvent ( "" ) ;
var result = await eventBus . Handle ( @event ) ;