ApplicationBus 1.0.1
dotnet add package ApplicationBus --version 1.0.1
NuGet\Install-Package ApplicationBus -Version 1.0.1
<PackageReference Include="ApplicationBus" Version="1.0.1" />
paket add ApplicationBus --version 1.0.1
#r "nuget: ApplicationBus, 1.0.1"
// Install ApplicationBus as a Cake Addin
#addin nuget:?package=ApplicationBus&version=1.0.1
// Install ApplicationBus as a Cake Tool
#tool nuget:?package=ApplicationBus&version=1.0.1
Service bus for use within an application.
Divide your application into decoupled services, and communicate between them through a messaging bus. This will reduce dependencies in the application through the use of asynchronous messages.
Define your messages:
public class MyMessage : MessageBase
{
// Unique Guid identifier for the message
public const string Message = "5a58526b-bb0a-4dba-9071-ea7d7c3ede53";
public static readonly Guid MsgId = new Guid(Message);
public MyMessage() : base(MsgId)
{
}
// Define any custom data for your message
public string CustomString {get; set;}
}
Define your services which will consume your messages:
public class MyService
{
private readonly Func<MessageBase> _createResponse;
private readonly HubService _hubService;
public RespondingTestHubService(IHubConfiguration hubConfig)
{
// The HubService class manages communication on the Bus.
_hubService = new HubService(hubConfig, this);
}
// Decorate the message handler for the message defined above.
// The method can be any name. The name is not important. No response is generated.
[HubMessageHandler(MyMessage.Message)]
public MessageBase ProcessMyMessage(Packet packet)
{
// packet contains message and routing information.
var descr = ((TestMessage) packet.Message).Description;
return null;
}
// Decorate the message handler for the message defined above.
// The method can be any name. The name is not important. No response is generated.
[HubMessageHandler(MyMessage.Message)]
public MessageBase ProcessMyMessage(Packet packet)
{
return new MyResponse();
}
}
Any class can send a message. Just include the HubService in it. If you define no message handlers (using the HubMessageHandler attribute), then it will process no messages, and can only send.
A command response pattern is also available. For a service to return a response, the handler just has to return a response message. That message will be sent only to the sender of the command message.
[HubMessageHandler(MyMessage.Message)]
public MessageBase ProcessMyMessage(Packet packet)
{
return new MyResponse();
}
The sending object calls the SendCommand method, which waits for all of the responses to be returned.
IEnumerable<MessageBase> responses = _hubService.SendCommand(msg);
The ServiceLibrarian allows discovering and creating services in your application. Your Service class needs to be decorated with the HubServiceClass attribute and implement the IHubServiceClass interface.
[HubServiceClass(description:"MyService", data:1)]
public class MyDiscoverableService : IHubServiceClass
{
private readonly HubService _hubService;
public void Start(IHubConfiguration hubConfig)
{
_hubService = new HubService(hubConfig, this);
}
public void Stop()
{
_hubService.Dispose();
}
}
You can then use the service librarian to discover and start the services:
var lib = new ServiceLibrarian();
lib.FindAndStart(hubCfg, (s, t) => s.Description == "MyService");
The hub configuration is a configuration object based on the IHubConfiguration class. It contains a single method to return the hub to use for the services. You can use multiple configuration objects to group the services on different busses.
A Singleton Hub is included which allows all of the services in your application to use the same hub.
public class SingletonHub : IHubConfiguration
{
private static readonly IHub Hub = new Hub();
public IHub GetHub() => Hub;
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 is compatible. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETCoreApp 2.1
- No dependencies.
-
.NETStandard 2.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.1 | 749 | 12/27/2018 |
Initial release.