Workleap.DomainEventPropagation.Abstractions
0.1.0-preview.31
Prefix Reserved
See the version list below for details.
dotnet add package Workleap.DomainEventPropagation.Abstractions --version 0.1.0-preview.31
NuGet\Install-Package Workleap.DomainEventPropagation.Abstractions -Version 0.1.0-preview.31
<PackageReference Include="Workleap.DomainEventPropagation.Abstractions" Version="0.1.0-preview.31" />
paket add Workleap.DomainEventPropagation.Abstractions --version 0.1.0-preview.31
#r "nuget: Workleap.DomainEventPropagation.Abstractions, 0.1.0-preview.31"
// Install Workleap.DomainEventPropagation.Abstractions as a Cake Addin #addin nuget:?package=Workleap.DomainEventPropagation.Abstractions&version=0.1.0-preview.31&prerelease // Install Workleap.DomainEventPropagation.Abstractions as a Cake Tool #tool nuget:?package=Workleap.DomainEventPropagation.Abstractions&version=0.1.0-preview.31&prerelease
Workleap.DomainEventPropagation
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 |
This set of three libraries is meant to be used in conjunction with Azure Event Grid in order to publish and receive domain events. It is meant to be used in a multi-services architecture where each service is responsible for its own data and publishes events to notify other services of changes.
Getting started
Publisher library
Install the package Workleap.DomainEventPropagation.Publishing in your webapi project that wants to send events to Event Grid. Then you can use on of the following methods to register the required services.
// Method 1: Lazily bind the options to a configuration section
services.AddEventPropagationPublisher();
services.AddOptions<EventPropagationPublisherOptions>()
.BindConfiguration(EventPropagationPublisherOptions.SectionName);
// appsetting.json
{
"EventPropagation": {
"TopicName": "<topic_name_to_publish_to>",
"TopicAccessKey": "<keyVault_provided_value>",
"TopicEndpoint": "<azure_topic_uri>"
}
}
// Method 2: Lazily bind the options to a configuration section and use a TokenCredential and RBAC
services.AddEventPropagationPublisher(opt =>
{
opt.TokenCredential = new DefaultAzureCredential();
});
services.AddOptions<EventPropagationPublisherOptions>()
.BindConfiguration(EventPropagationPublisherOptions.SectionName);
// appsetting.json
{
"EventPropagation": {
"TopicName": "<topic_name_to_publish_to>",
"TopicEndpoint": "<azure_topic_uri>"
}
}
// Method 3: Set options values directly in C# using and access key
services.AddEventPropagationPublisher(opt =>
{
opt.TopicName = "<topic_name_to_publish_to>",
opt.TopicEndpoint = "<azure_topic_uri>",
opt.TopicAccessKey = "<provided from keyVault>"
});
// Method 4: Set options values directly in C# using a TokenCredential and RBAC
services.AddEventPropagationPublisher(opt =>
{
opt.TopicName = "<topic_name_to_publish_to>",
opt.TopicEndpoint = "<azure_topic_uri>",
o.TokenCredential = new DefaultAzureCredential())
}
Note that you can use either an access key or a token credentials in order to authenticate with your eventGrid topic but not both.
Now in order to publish a domain event, you first need to define your domain events using the IDomainEvent
interface.
public class ExampleDomainEvent : IDomainEvent
{
public string Id { get; set; }
public DateTime Date { get; set; }
}
Once your domain events are defined, you can use the IEventPropagationClient
interface (via dependency injection).
var domainEvent = new ExampleDomainEvent
{
Id = Guid.NewGuid().ToString(),
Date = DateTime.UtcNow
};
await this._eventPropagationClient.PublishDomainEventAsync(subject: "TestEventPublication", domainEvent);
Subscriber library
Install the package Workleap.DomainEventPropagation.Subscription in your webapi project that wants to receive events from Event Grid. Then you can use on of the following methods to register the required services.
// Method 1: Register only selected domain event handlers
services.AddEventPropagationSubscriber()
.AddDomainEventHandler<ExampleDomainEventHandler>()
.AddDomainEventHandler<SampleDomainEventHandler>();
// Method 2: Register all domain event handlers from an assembly
services
.AddEventPropagationSubscriber()
.AddDomainEventHandlersFromAssembly(Assembly.GetExecutingAssembly());
// Register the webhook endpoint
app.UseEndpoints(endpointBuilder =>
{
endpointBuilder
.AddEventPropagationEndpoint()
.WithAuthorization();
});
You can define your domain event handlers by implementing the IDomainEventHandler<>
interface and then registering them in the service collection as shown above.
public class ExampleDomainEventHandler : IDomainEventHandler<ExampleDomainEvent>
{
public Task HandleDomainEventAsync(ExampleDomainEvent domainEvent, CancellationToken cancellationToken)
{
return Task.CompletedTask;
}
}
Securing your webhook endpoint
It is required to expose an endpoint in order for eventGrid to be able to push events. By default, the registered endpoint will allow anonymous access, but it is possible to secure it as shown below:
app.UseEndpoints(endpointBuilder =>
{
endpointBuilder
.AddEventPropagationEndpoint()
.WithAuthorization(); // This here will add an authorize attribute to the endpoint requiring a valid JTW access token.
});
Now that your api endpoint is secure with an authorize attribute, you just need to follow the remaining steps:
- Create a
AzureEventGridSecureWebhookSubscriber
role on your webhook application's app registration. - Grant said role to Microsoft.EventGrid service principal
- Create a webhook EventGrid subscription and specify the TenantId and webhook applicationId
For more details about each of those steps, you can follow this Microsoft documentation.
Additional Notes
- 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).
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
- No dependencies.
NuGet packages (3)
Showing the top 3 NuGet packages that depend on Workleap.DomainEventPropagation.Abstractions:
Package | Downloads |
---|---|
Workleap.DomainEventPropagation.Subscription
Propagate domain events with Azure |
|
Workleap.DomainEventPropagation.Publishing
Propagate domain events with Azure |
|
Workleap.DomainEventPropagation.Subscription.PullDelivery
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.9 | 40 | 12/18/2024 |
1.1.1-preview.8 | 40 | 12/18/2024 |
1.1.1-preview.7 | 40 | 12/17/2024 |
1.1.1-preview.6 | 40 | 11/29/2024 |
1.1.1-preview.5 | 41 | 11/17/2024 |
1.1.1-preview.4 | 43 | 10/30/2024 |
1.1.1-preview.3 | 44 | 10/28/2024 |
1.1.1-preview.2 | 41 | 10/28/2024 |
1.1.1-preview.1 | 41 | 10/28/2024 |
1.1.0 | 6,386 | 10/9/2024 |
1.0.2-preview.19 | 52 | 10/9/2024 |
1.0.2-preview.18 | 52 | 10/1/2024 |
1.0.2-preview.17 | 48 | 10/1/2024 |
1.0.2-preview.16 | 48 | 10/1/2024 |
1.0.2-preview.15 | 50 | 10/1/2024 |
1.0.2-preview.14 | 45 | 10/1/2024 |
1.0.2-preview.13 | 37 | 9/20/2024 |
1.0.2-preview.12 | 38 | 9/20/2024 |
1.0.2-preview.11 | 49 | 8/27/2024 |
1.0.2-preview.10 | 47 | 8/27/2024 |
1.0.2-preview.9 | 48 | 8/27/2024 |
1.0.2-preview.7 | 42 | 8/27/2024 |
1.0.2-preview.5 | 45 | 8/27/2024 |
1.0.2-preview.4 | 44 | 8/27/2024 |
1.0.2-preview.3 | 41 | 8/27/2024 |
1.0.2-preview.2 | 46 | 8/27/2024 |
1.0.1 | 5,068 | 8/20/2024 |
1.0.1-preview.2 | 66 | 8/20/2024 |
1.0.1-preview.1 | 65 | 8/16/2024 |
1.0.0 | 449 | 8/15/2024 |
0.6.2-preview.2 | 72 | 8/15/2024 |
0.6.2-preview.1 | 67 | 8/15/2024 |
0.6.1 | 8,108 | 8/15/2024 |
0.6.1-preview.5 | 69 | 8/14/2024 |
0.6.1-preview.4 | 61 | 8/14/2024 |
0.6.1-preview.3 | 63 | 8/12/2024 |
0.6.1-preview.2 | 36 | 8/5/2024 |
0.6.1-preview.1 | 152 | 7/26/2024 |
0.6.0 | 2,181 | 7/18/2024 |
0.5.6-preview.3 | 57 | 7/18/2024 |
0.5.6-preview.2 | 59 | 7/18/2024 |
0.5.6-preview.1 | 58 | 7/18/2024 |
0.5.5-preview.3 | 42 | 7/17/2024 |
0.5.5-preview.2 | 49 | 7/15/2024 |
0.5.4 | 5,567 | 6/19/2024 |
0.5.4-preview.5 | 52 | 6/17/2024 |
0.5.4-preview.4 | 53 | 6/17/2024 |
0.5.4-preview.3 | 52 | 6/14/2024 |
0.5.4-preview.2 | 66 | 6/14/2024 |
0.5.4-preview.1 | 50 | 6/13/2024 |
0.5.3 | 5,396 | 5/21/2024 |
0.5.3-preview.1 | 61 | 5/10/2024 |
0.5.2 | 60,005 | 4/17/2024 |
0.5.2-preview.2 | 75 | 4/12/2024 |
0.5.2-preview.1 | 217 | 4/8/2024 |
0.5.1 | 3,693 | 4/8/2024 |
0.5.1-preview.1 | 58 | 4/8/2024 |
0.4.1-preview.10 | 61 | 4/8/2024 |
0.4.1-preview.9 | 67 | 3/28/2024 |
0.4.1-preview.8 | 73 | 3/26/2024 |
0.4.1-preview.7 | 68 | 3/19/2024 |
0.4.1-preview.6 | 55 | 3/18/2024 |
0.4.1-preview.5 | 64 | 3/8/2024 |
0.4.1-preview.4 | 63 | 3/7/2024 |
0.4.1-preview.3 | 349 | 3/4/2024 |
0.4.1-preview.2 | 59 | 3/4/2024 |
0.4.1-preview.1 | 60 | 2/29/2024 |
0.4.0 | 20,558 | 2/27/2024 |
0.3.1-preview.6 | 62 | 2/26/2024 |
0.3.1-preview.5 | 59 | 2/26/2024 |
0.3.1-preview.4 | 62 | 2/23/2024 |
0.3.1-preview.3 | 59 | 2/16/2024 |
0.3.1-preview.2 | 80 | 2/6/2024 |
0.3.1-preview.1 | 449 | 2/6/2024 |
0.3.0 | 33,039 | 1/26/2024 |
0.2.1-preview.24 | 59 | 1/23/2024 |
0.2.1-preview.23 | 63 | 1/22/2024 |
0.2.1-preview.22 | 72 | 1/12/2024 |
0.2.1-preview.21 | 67 | 1/12/2024 |
0.2.1-preview.20 | 64 | 1/12/2024 |
0.2.1-preview.18 | 82 | 12/18/2023 |
0.2.1-preview.17 | 103 | 12/7/2023 |
0.2.1-preview.16 | 108 | 11/17/2023 |
0.2.1-preview.15 | 95 | 11/13/2023 |
0.2.1-preview.14 | 74 | 11/13/2023 |
0.2.1-preview.13 | 77 | 11/7/2023 |
0.2.1-preview.11 | 131 | 10/24/2023 |
0.2.1-preview.10 | 83 | 10/20/2023 |
0.2.1-preview.8 | 87 | 10/17/2023 |
0.2.1-preview.7 | 88 | 10/13/2023 |
0.2.1-preview.6 | 80 | 10/2/2023 |
0.2.1-preview.5 | 83 | 9/26/2023 |
0.2.1-preview.4 | 69 | 9/21/2023 |
0.2.1-preview.3 | 78 | 9/21/2023 |
0.2.1-preview.2 | 74 | 9/21/2023 |
0.2.1-preview.1 | 83 | 9/21/2023 |
0.2.0 | 52,602 | 9/21/2023 |
0.1.1-preview.6 | 82 | 9/20/2023 |
0.1.1-preview.5 | 78 | 9/20/2023 |
0.1.1-preview.4 | 79 | 9/19/2023 |
0.1.1-preview.3 | 103 | 9/13/2023 |
0.1.1-preview.2 | 86 | 9/13/2023 |
0.1.1-preview.1 | 89 | 9/11/2023 |
0.1.0 | 653 | 9/7/2023 |
0.1.0-preview.33 | 91 | 9/7/2023 |
0.1.0-preview.32 | 86 | 8/25/2023 |
0.1.0-preview.31 | 72 | 8/22/2023 |
0.1.0-preview.30 | 74 | 8/18/2023 |
0.1.0-preview.29 | 76 | 8/16/2023 |
0.1.0-preview.28 | 79 | 8/16/2023 |
0.1.0-preview.27 | 84 | 8/15/2023 |
0.1.0-preview.26 | 87 | 8/14/2023 |
0.1.0-preview.24 | 89 | 8/10/2023 |
0.1.0-preview.23 | 98 | 8/9/2023 |
0.1.0-preview.22 | 95 | 8/4/2023 |
0.1.0-preview.21 | 86 | 8/4/2023 |
0.1.0-preview.20 | 88 | 8/3/2023 |
0.1.0-preview.19 | 100 | 8/1/2023 |
0.1.0-preview.17 | 87 | 8/1/2023 |