Coder Social home page Coder Social logo

lightmessagebus's Introduction

What is LightMessageBus?

A simple, light-weight application level event aggregator which facilitates the exchange of messages between objects without direct references.

Use-cases and examples?

A soundComponent needs to be notified whenever a user clicks on any button.

MessageBus.Default.FromAny().Where<ButtonClickMessage>().Notify(soundComponent)

A taxCalculator needs to be notified whenever shopping cart is changed.

MessageBus.Default.From(shoppingCart).Notify(taxCalculator);

How is this achieved?

LightMessageBus uses a simple publisher/subscriber pattern.

  • Subscribers use the MessageBus to subscribe to messages they wish to be notified about. They may wish to filter messages by the source, type of message or some other predicate.
  • Publishers use the MessageBus to publish messages to the potential subscribers
  • Neither subscribers nor publishers have any references to each other. They simply use a common communication channel - the MessageBus

How does that help?

The pub/sub pattern enables you to promote decoupled architecture in your application. Since there is no need for various objects (views, models, controllers, ...) to know of each other existence - you are free to develop them independently in isolation. Such architecture enables testing, refactoring and limits the propagation of changes through the system.

Why not use delegates/events?

Using delegates and/or events requires a reference between the publisher and the subscriber (subscribers reference publishers or vice-versa). Any change to the referenced class will affect the other. Such change may even propagate through the system resulting in significant changes due to a small cause.

How is it used?

LightMessageBus uses LINQ-like, fluent syntax for maximum readability and flexibility. The basic building blocks of a LightMessageBus registration expression are: From, Where and Notify.

First we define the publishers:

  • From - specifies publisher(s) of interest to subscriber.
  • FromAny - specifies any publisher.

Next we optionally define the messages:

  • Where - specifies the types of messages of interest to subscriber.

Lastly we define the subscriber:

  • Notify - specifies the subscriber.

lightmessagebus's People

Contributors

goransiska avatar mihamarkic avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.