Workleap.DomainEventPropagation.Publishing
0.1.0-preview.30
Prefix Reserved
See the version list below for details.
dotnet add package Workleap.DomainEventPropagation.Publishing --version 0.1.0-preview.30
NuGet\Install-Package Workleap.DomainEventPropagation.Publishing -Version 0.1.0-preview.30
<PackageReference Include="Workleap.DomainEventPropagation.Publishing" Version="0.1.0-preview.30" />
paket add Workleap.DomainEventPropagation.Publishing --version 0.1.0-preview.30
#r "nuget: Workleap.DomainEventPropagation.Publishing, 0.1.0-preview.30"
// Install Workleap.DomainEventPropagation.Publishing as a Cake Addin #addin nuget:?package=Workleap.DomainEventPropagation.Publishing&version=0.1.0-preview.30&prerelease // Install Workleap.DomainEventPropagation.Publishing as a Cake Tool #tool nuget:?package=Workleap.DomainEventPropagation.Publishing&version=0.1.0-preview.30&prerelease
Workleap.DomainEventPropagation
Getting started
Package | Download Link | Description |
---|---|---|
Workleap.DomainEventPropagation.Abstractions | Contains abstractions that are used for publishing and receiving events | |
Workleap.DomainEventPropagation.Publishing | Contains classes to publish events | |
Workleap.DomainEventPropagation.Subscription | Contains classes to subscribe to topics and receive events |
What does the Workleap.DomainEventPropagation.* packages do?
- Create webhook endpoint and interfaces for receiving events
- Allow publishing events to Event Grid topics
Using the Workleap.DomainEventPropagation.Publishing package to publish events
When using dotnet core, you can register event propagation at startup in the service collection.
// Method 1: Lazily bind the options to a configuration section
services.AddEventPropagationPublisher();
services.AddOptions<EventPropagationPublisherOptions>().BindConfiguration(EventPropagationPublisherOptions.SectionName);
// Method 2: Set options values directly in C#
services.AddEventPropagationPublisher(opt =>
{
opt.TopicName = "<topic_name_to_publish_to>",
opt.TopicAccessKey = "<provided from keyVault>",
opt.TopicEndpoint = "<azure_topic_uri>"
});
// Method 3: Use RBAC
services.AddEventPropagationPublisher(o => o.TokenCredential = new ManagedIdentityCredential());
Configuration is required. Configuration can be loaded from the appsettings file by passing the IConfiguration instance (see above). The topic access key should be stored securely in a key vault.
{
"EventPropagation": {
"TopicName": "<topic_name_to_publish_to>",
"TopicAccessKey": "<keyVault_provided_value>",
"TopicEndpoint": "<azure_topic_uri>"
}
}
To publish an event, use the IEventPropagationClient
interface (via dependency injection). Use the PublishDomainEventAsync
to publish the event. The required subject parameter is a string description to provide context for the event.
var domainEvent = new ExampleDomainEvent
{
Id = Guid.NewGuid().ToString(),
Date = DateTime.UtcNow
};
await this._eventPropagationClient.PublishDomainEventAsync(subject: "TestEventPublication", domainEvent);
Using the Workleap.EventPropagation.Subscription package to subscribe to events
When using ASP.NET Core with .NET 6+, you can register event propagation subscriptions at startup in the service collection. To configure the subscriber, the list of subscribed topics is required.
services
.AddEventPropagationSubscriber()
.AddDomainEventHandlersFromAssembly(Assembly.GetExecutingAssembly());
// or add a single domain event handler
.AddDomainEventHandler<ExampleDomainEventHandler>()
This can be used to register endpoint to receive events
app.UseRouting();
...
app.UseEndpoints(builder =>
{
builder.AddEventPropagationEndpoints();
});
Define domain event handlers
You must define domain event handlers for events you wish to handle. You are not obligated to handle every possible event from a topic.
Domain event handlers must implement the IDomainEventHandler<>
interface.
public class ExampleDomainEventHandler : IDomainEventHandler<ExampleDomainEvent>
{
public Task HandleDomainEventAsync(ExampleDomainEvent domainEvent, CancellationToken cancellationToken)
{
return Task.CompletedTask;
}
}
Restrictions
- You may only define one domain event handler per domain event you wish to handle. If you would require more, use the single allowed domain event handler as a facade for multiple operations.
- DomainEventHandlers must have idempotent behavior (you could execute it multiple times for the same event and the result would always be the same).
- DomainEventHandlers should use the property DataVersion (when necessary)
Exposing domain events
To expose your service’s domain events, you must provide a NuGet package with all domain (class) definitions. Your project must reference the Workleap.DomainEventPropagation.Abstractions package and your domain events must implement the IDomainEvent interface.
public class ExampleDomainEvent : IDomainEvent
{
public string Id { get; set; }
public DateTime Date { get; set; }
public string DataVersion => "1";
}
It is recommended to use a separate pipeline to publish domain event definitions. Any existing pipeline can be reused with minor tweaks to achieve this.
Restrictions
- Domain events must only contain Ids and types (any content is optional). In some rare cases, an immutable field could be added to the event, however this comes at risk of exposing PII information.
- Changes to domain events should be additive
- Domain events must implement the DataVersion property
- Domain event projects should follow the pattern Workleap.[Service].[DomainEvents] (Service would usually match the topic name).
- Event Grid limits event size to 64 kb. This means a regular event could contain a maximum of about 1500 Guid ids. Keep in mind the size restriction when sending batch events. Do not hesitate to split a larger event into multiple, smaller domain events.
Building, releasing and versioning
The project can be built by running Build.ps1
. It uses Microsoft.CodeAnalysis.PublicApiAnalyzers to help detect public API breaking changes. Use the built-in roslyn analyzer to ensure that public APIs are declared in PublicAPI.Shipped.txt
, and obsolete public APIs in PublicAPI.Unshipped.txt
.
A new preview NuGet package is automatically published on any new commit on the main branch. This means that by completing a pull request, you automatically get a new NuGet package.
When you are ready to officially release a stable NuGet package by following the SemVer guidelines, simply manually create a tag with the format x.y.z
. This will automatically create and publish a NuGet package for this version.
License
Copyright © 2023, Workleap This code is licensed under the Apache License, Version 2.0. You may obtain a copy of this license at https://github.com/gsoft-inc/gsoft-license/blob/master/LICENSE.
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 was computed. 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. |
-
.NETStandard 2.0
- Azure.Messaging.EventGrid (>= 4.17.0)
- Microsoft.Extensions.Azure (>= 1.6.3)
- Microsoft.Extensions.Configuration (>= 6.0.1)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 6.0.0)
- Microsoft.Extensions.Hosting (>= 6.0.1)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 6.0.0)
- System.Text.Json (>= 6.0.0)
- Workleap.DomainEventPropagation.Abstractions (>= 0.1.0-preview.30)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Workleap.DomainEventPropagation.Publishing:
Package | Downloads |
---|---|
Workleap.DomainEventPropagation.Publishing.ApplicationInsights
Propagate domain events with Azure |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.1.1-preview.5 | 30 | 11/17/2024 |
1.1.1-preview.4 | 36 | 10/30/2024 |
1.1.1-preview.3 | 39 | 10/28/2024 |
1.1.1-preview.2 | 37 | 10/28/2024 |
1.1.1-preview.1 | 35 | 10/28/2024 |
1.1.0 | 1,422 | 10/9/2024 |
1.0.2-preview.19 | 44 | 10/9/2024 |
1.0.2-preview.18 | 47 | 10/1/2024 |
1.0.2-preview.17 | 44 | 10/1/2024 |
1.0.2-preview.16 | 45 | 10/1/2024 |
1.0.2-preview.15 | 43 | 10/1/2024 |
1.0.2-preview.14 | 39 | 10/1/2024 |
1.0.2-preview.13 | 32 | 9/20/2024 |
1.0.2-preview.12 | 29 | 9/20/2024 |
1.0.2-preview.11 | 45 | 8/27/2024 |
1.0.2-preview.10 | 41 | 8/27/2024 |
1.0.2-preview.9 | 46 | 8/27/2024 |
1.0.2-preview.7 | 41 | 8/27/2024 |
1.0.2-preview.5 | 40 | 8/27/2024 |
1.0.2-preview.4 | 37 | 8/27/2024 |
1.0.2-preview.3 | 40 | 8/27/2024 |
1.0.2-preview.2 | 41 | 8/27/2024 |
1.0.1 | 2,078 | 8/20/2024 |
1.0.1-preview.2 | 63 | 8/20/2024 |
1.0.1-preview.1 | 62 | 8/16/2024 |
1.0.0 | 218 | 8/15/2024 |
0.6.2-preview.2 | 64 | 8/15/2024 |
0.6.2-preview.1 | 59 | 8/15/2024 |
0.6.1 | 2,727 | 8/15/2024 |
0.6.1-preview.5 | 65 | 8/14/2024 |
0.6.1-preview.4 | 59 | 8/14/2024 |
0.6.1-preview.3 | 61 | 8/12/2024 |
0.6.1-preview.2 | 33 | 8/5/2024 |
0.6.1-preview.1 | 44 | 7/26/2024 |
0.6.0 | 489 | 7/18/2024 |
0.5.6-preview.3 | 50 | 7/18/2024 |
0.5.6-preview.2 | 52 | 7/18/2024 |
0.5.6-preview.1 | 50 | 7/18/2024 |
0.5.5-preview.3 | 38 | 7/17/2024 |
0.5.5-preview.2 | 47 | 7/15/2024 |
0.5.4 | 2,826 | 6/19/2024 |
0.5.4-preview.5 | 50 | 6/17/2024 |
0.5.4-preview.4 | 48 | 6/17/2024 |
0.5.4-preview.3 | 52 | 6/14/2024 |
0.5.4-preview.2 | 48 | 6/14/2024 |
0.5.4-preview.1 | 46 | 6/13/2024 |
0.5.3 | 1,442 | 5/21/2024 |
0.5.3-preview.1 | 63 | 5/10/2024 |
0.5.2 | 4,931 | 4/17/2024 |
0.5.2-preview.2 | 72 | 4/12/2024 |
0.5.2-preview.1 | 177 | 4/8/2024 |
0.5.1 | 1,131 | 4/8/2024 |
0.5.1-preview.1 | 62 | 4/8/2024 |
0.4.1-preview.10 | 69 | 4/8/2024 |
0.4.1-preview.9 | 59 | 3/28/2024 |
0.4.1-preview.8 | 61 | 3/26/2024 |
0.4.1-preview.7 | 71 | 3/19/2024 |
0.4.1-preview.6 | 56 | 3/18/2024 |
0.4.1-preview.5 | 51 | 3/8/2024 |
0.4.1-preview.4 | 58 | 3/7/2024 |
0.4.1-preview.3 | 60 | 3/4/2024 |
0.4.1-preview.2 | 55 | 3/4/2024 |
0.4.1-preview.1 | 56 | 2/29/2024 |
0.4.0 | 4,632 | 2/27/2024 |
0.3.1-preview.6 | 64 | 2/26/2024 |
0.3.1-preview.5 | 54 | 2/26/2024 |
0.3.1-preview.4 | 63 | 2/23/2024 |
0.3.1-preview.3 | 63 | 2/16/2024 |
0.3.1-preview.2 | 74 | 2/6/2024 |
0.3.1-preview.1 | 335 | 2/6/2024 |
0.3.0 | 2,087 | 1/26/2024 |
0.2.1-preview.24 | 55 | 1/23/2024 |
0.2.1-preview.23 | 56 | 1/22/2024 |
0.2.1-preview.22 | 61 | 1/12/2024 |
0.2.1-preview.21 | 57 | 1/12/2024 |
0.2.1-preview.20 | 60 | 1/12/2024 |
0.2.1-preview.18 | 72 | 12/18/2023 |
0.2.1-preview.17 | 93 | 12/7/2023 |
0.2.1-preview.16 | 109 | 11/17/2023 |
0.2.1-preview.15 | 92 | 11/13/2023 |
0.2.1-preview.14 | 63 | 11/13/2023 |
0.2.1-preview.13 | 74 | 11/7/2023 |
0.2.1-preview.11 | 134 | 10/24/2023 |
0.2.1-preview.10 | 82 | 10/20/2023 |
0.2.1-preview.8 | 83 | 10/17/2023 |
0.2.1-preview.7 | 84 | 10/13/2023 |
0.2.1-preview.6 | 71 | 10/2/2023 |
0.2.1-preview.5 | 77 | 9/26/2023 |
0.2.1-preview.4 | 64 | 9/21/2023 |
0.2.1-preview.3 | 69 | 9/21/2023 |
0.2.1-preview.2 | 79 | 9/21/2023 |
0.2.1-preview.1 | 74 | 9/21/2023 |
0.2.0 | 8,938 | 9/21/2023 |
0.1.1-preview.6 | 78 | 9/20/2023 |
0.1.1-preview.5 | 71 | 9/20/2023 |
0.1.1-preview.4 | 86 | 9/19/2023 |
0.1.1-preview.3 | 91 | 9/13/2023 |
0.1.1-preview.2 | 81 | 9/13/2023 |
0.1.1-preview.1 | 90 | 9/11/2023 |
0.1.0 | 216 | 9/7/2023 |
0.1.0-preview.33 | 84 | 9/7/2023 |
0.1.0-preview.32 | 83 | 8/25/2023 |
0.1.0-preview.31 | 81 | 8/22/2023 |
0.1.0-preview.30 | 73 | 8/18/2023 |
0.1.0-preview.29 | 82 | 8/16/2023 |
0.1.0-preview.28 | 78 | 8/16/2023 |
0.1.0-preview.27 | 79 | 8/15/2023 |
0.1.0-preview.26 | 77 | 8/14/2023 |
0.1.0-preview.24 | 86 | 8/10/2023 |
0.1.0-preview.23 | 97 | 8/9/2023 |
0.1.0-preview.22 | 89 | 8/4/2023 |
0.1.0-preview.21 | 84 | 8/4/2023 |
0.1.0-preview.20 | 84 | 8/3/2023 |
0.1.0-preview.19 | 87 | 8/1/2023 |
0.1.0-preview.17 | 93 | 8/1/2023 |