mxjones / redbus Goto Github PK
View Code? Open in Web Editor NEWA simple EventBus / MessageBus library in C#
License: MIT License
A simple EventBus / MessageBus library in C#
License: MIT License
I think that doing this it's dangerous, you shouldn't do this:
https://github.com/mxjones/RedBus/blob/master/src/Redbus/Redbus/EventBus.cs#L86
There's a concurrency issue in EventBus.Publish
. When enumerating allSubscriptions
for publishing, it's possible that a subscription has unsubscribed since allSubscriptions
was assigned. This will result in an IndexOutOfBoundsException
.
Related to #1.
It would be great to have a separate package for Interfaces (e.g. Redbus.Abstractions
). The main need I have for this is that I want my domain project to have a reference to Redbus.Abstractions
package but don't want it to have a reference to concrete implementation of the event bus so that it prevents direct coupling to the implementation.
I am happy to contribute this but wanted to check with you first to see if this would be something you are up to having.
Hi, I found an issue that if you have for example this wrapper:
private static readonly IEventBus EventBus;
public static void Publish(EventBase message)
{
EventBus.Publish(message);
}
// in another class
EventBusWrapper.Publish(new Payload(payload))
EventBus cannot find any event except EventBase.
But if you declare the method as below, everything works as should:
public static void Publish<T>(T message) where T : EventBase
{
EventBus.Publish(message);
}
I spent a few hours to find a root cause. Maybe it saves time for others.
It does nothing, it doesn't have any body. Instead of an abstract class it would be nice if it was an interface 'IEvent' or similar.
https://github.com/mxjones/RedBus/blob/master/src/Redbus/Redbus/Events/EventBase.cs
Hi,
Thanks for your work, but there is an issue in EventBus, where you use a for-each to alter a collection.
I have fixed it by using a normal for instead:
`public void Publish<TEventBase>(TEventBase eventItem) where TEventBase : EventBase
{
if (eventItem == null)
throw new ArgumentNullException("eventItem");
List<ISubscription> allSubscriptions = new List<ISubscription>();
lock (SubscriptionsLock)
{
if (_subscriptions.ContainsKey(typeof(TEventBase)))
allSubscriptions = _subscriptions[typeof(TEventBase)];
}
for (int listIndex = allSubscriptions.Count - 1; listIndex >= 0; listIndex--)
{
try
{
allSubscriptions[listIndex].Publish(eventItem);
}
catch (Exception exception)
{
}
}
}`
Regards :)
I want to use your library (.NET Standard 2.0) but it adds some dependencies that are not necessary and I don't want them in my project.
https://github.com/mxjones/RedBus/blob/master/src/Redbus/Redbus/Redbus.csproj
You can remove this block and it will compile fine.
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
<PackageReference Include="System.Reflection.Emit.LightWeight" Version="4.3.0" />
<PackageReference Include="System.Dynamic.Runtime" Version="4.3.0" />
<PackageReference Include="Microsoft.CSharp" Version="4.3.0" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net45' ">
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.