Share
nvents

.NET events across the network

Performance improvements and inheritance support in nvents 0.4

How nvents handles subscribers

Prior to version 0.4 nvents searched for subscribers and opened the connection to each server on every publish.

Nvents 0.4 keeps the connections open and sends the publish event to known subscribers before searching for more subscribers. This, of course, dramatically increases the performance.

Automatic support for inheritance

using System; using Nvents; namespace NventsInheritanceSample { class Program { static void Main(string[] args) { Events.Subscribe<ICustomerEvent>( e => Console.WriteLine("Something happend with customer {0}", e.CustomerId)); Events.Subscribe<CustomerAddedEvent>( e => Console.WriteLine("Customer {0} was added", e.CustomerId)); Events.Subscribe<CustomerChangedEvent>( e => Console.WriteLine("Customer {0} changed", e.CustomerId)); Events.Subscribe<CustomerNameChangedEvent>( e => Console.WriteLine("Customer {0} changed name from {1} to {2}", e.CustomerId, e.OldName, e.NewName)); Events.Publish(new CustomerNameChangedEvent { CustomerId = 1, OldName = "Old Name", NewName = "New Name" }); Events.Publish(new CustomerAddedEvent { CustomerId = 2 }); Console.ReadLine(); } } public interface ICustomerEvent : IEvent { int CustomerId { get; set; } } public class CustomerAddedEvent : ICustomerEvent { public int CustomerId { get; set; } } public class CustomerChangedEvent : ICustomerEvent { public int CustomerId { get; set; } } public class CustomerNameChangedEvent : CustomerChangedEvent { public string OldName { get; set; } public string NewName { get; set; } } }

Will output the following statements

Something happend with customer 1
Customer 1 changed
Something happend with customer 2
Customer 1 changed name from Old Name to New Name
Customer 2 was added

Tags:

 
Fork me on GitHub