-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Getting Started section with sample (#133)
* Refactored sample * Added TransactionalBox.Sample.WebApi.InMemory * Added Getting Started section in docs * Refactored sample for learning
- Loading branch information
Showing
13 changed files
with
313 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
samples/TransactionalBox.Sample.WebApi.InMemory/Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using TransactionalBox; | ||
using TransactionalBox.Outbox; | ||
using TransactionalBox.Outbox.Storage.InMemory; | ||
using TransactionalBox.OutboxWorker; | ||
using TransactionalBox.OutboxWorker.Storage.InMemory; | ||
using TransactionalBox.OutboxWorker.Transport.InMemory; | ||
using TransactionalBox.InboxWorker; | ||
using TransactionalBox.InboxWorker.Transport.InMemory; | ||
using TransactionalBox.InboxWorker.Storage.InMemory; | ||
using TransactionalBox.Inbox; | ||
using TransactionalBox.Inbox.Storage.InMemory; | ||
using TransactionalBox.Base.Inbox.Storage.InMemory; | ||
using TransactionalBox.Base.Outbox.Storage.InMemory; | ||
using Microsoft.AspNetCore.Mvc; | ||
using TransactionalBox.Sample.WebApi.InMemory.ServiceWithOutbox; | ||
|
||
var builder = WebApplication.CreateBuilder(args); | ||
|
||
builder.Services.AddEndpointsApiExplorer(); | ||
builder.Services.AddSwaggerGen(); | ||
builder.Services.AddScoped<ExampleServiceWithOutbox>(); | ||
|
||
builder.Services.AddTransactionalBox(x => | ||
{ | ||
x.AddOutbox(storage => storage.UseInMemory()) | ||
.WithWorker( | ||
storage => storage.UseInMemory(), | ||
transport => transport.UseInMemory()); | ||
|
||
x.AddInbox(storage => storage.UseInMemory()) | ||
.WithWorker( | ||
storage => storage.UseInMemory(), | ||
transport => transport.UseInMemory()); | ||
}, | ||
settings => settings.ServiceId = "ServiceName"); | ||
|
||
var app = builder.Build(); | ||
|
||
// Configure the HTTP request pipeline. | ||
if (app.Environment.IsDevelopment()) | ||
{ | ||
app.UseSwagger(); | ||
app.UseSwaggerUI(); | ||
} | ||
|
||
app.UseHttpsRedirection(); | ||
|
||
app.MapPost("/add-message-to-outbox", async (ExampleServiceWithOutbox exampleServiceWithOutbox) => await exampleServiceWithOutbox.Execute()); | ||
|
||
app.MapGet("/get-messages-from-outbox", async (IOutboxStorageReadOnly outboxStorageReadOnly) => outboxStorageReadOnly.OutboxMessages); | ||
|
||
app.MapGet("/get-messages-from-inbox", async (IInboxStorageReadOnly inboxStorage) => inboxStorage.InboxMessages); | ||
|
||
app.MapGet("/get-idempotent-messages-from-inbox", async (IInboxStorageReadOnly inboxStorage) => inboxStorage.IdempotentInboxKeys); | ||
|
||
app.Run(); |
41 changes: 41 additions & 0 deletions
41
samples/TransactionalBox.Sample.WebApi.InMemory/Properties/launchSettings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{ | ||
"$schema": "http://json.schemastore.org/launchsettings.json", | ||
"iisSettings": { | ||
"windowsAuthentication": false, | ||
"anonymousAuthentication": true, | ||
"iisExpress": { | ||
"applicationUrl": "http://localhost:1454", | ||
"sslPort": 44334 | ||
} | ||
}, | ||
"profiles": { | ||
"http": { | ||
"commandName": "Project", | ||
"dotnetRunMessages": true, | ||
"launchBrowser": true, | ||
"launchUrl": "swagger", | ||
"applicationUrl": "http://localhost:5152", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
}, | ||
"https": { | ||
"commandName": "Project", | ||
"dotnetRunMessages": true, | ||
"launchBrowser": true, | ||
"launchUrl": "swagger", | ||
"applicationUrl": "https://localhost:7070;http://localhost:5152", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
}, | ||
"IIS Express": { | ||
"commandName": "IISExpress", | ||
"launchBrowser": true, | ||
"launchUrl": "swagger", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
samples/TransactionalBox.Sample.WebApi.InMemory/ServiceWithInbox/ExampleMessage.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using TransactionalBox.Inbox; | ||
|
||
namespace TransactionalBox.Sample.WebApi.InMemory.ServiceWithInbox | ||
{ | ||
public sealed class ExampleMessage : IInboxMessage | ||
{ | ||
public string Name { get; init; } | ||
|
||
public int Age { get; init; } | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
samples/TransactionalBox.Sample.WebApi.InMemory/ServiceWithInbox/ExampleMessageHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using TransactionalBox.Inbox; | ||
using TransactionalBox.Inbox.Contexts; | ||
|
||
namespace TransactionalBox.Sample.WebApi.InMemory.ServiceWithInbox | ||
{ | ||
internal sealed class ExampleMessageHandler : IInboxMessageHandler<ExampleMessage> | ||
{ | ||
public async Task Handle(ExampleMessage message, IExecutionContext executionContext) | ||
{ | ||
// Your Logic | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
samples/TransactionalBox.Sample.WebApi.InMemory/ServiceWithOutbox/ExampleMessage.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using TransactionalBox.Outbox; | ||
|
||
namespace TransactionalBox.Sample.WebApi.InMemory.ServiceWithOutbox | ||
{ | ||
public sealed class ExampleMessage : IOutboxMessage | ||
{ | ||
public string Name { get; init; } | ||
|
||
public int Age { get; init; } | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...les/TransactionalBox.Sample.WebApi.InMemory/ServiceWithOutbox/ExampleServiceWithOutbox.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using TransactionalBox.Outbox; | ||
|
||
namespace TransactionalBox.Sample.WebApi.InMemory.ServiceWithOutbox | ||
{ | ||
public sealed class ExampleServiceWithOutbox | ||
{ | ||
private readonly IOutbox _outbox; | ||
|
||
public ExampleServiceWithOutbox(IOutbox outbox) | ||
{ | ||
_outbox = outbox; | ||
} | ||
|
||
public async Task Execute() | ||
{ | ||
var message = new ExampleMessage() | ||
{ | ||
Name = "Name", | ||
Age = 25, | ||
}; | ||
|
||
await _outbox.Add(message, envelope => envelope.Receiver = "ServiceName"); | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...es/TransactionalBox.Sample.WebApi.InMemory/TransactionalBox.Sample.WebApi.InMemory.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<InvariantGlobalization>true</InvariantGlobalization> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" /> | ||
<PackageReference Include="Swashbuckle.AspNetCore" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\source\TransactionalBox.Inbox.Storage.InMemory\TransactionalBox.Inbox.Storage.InMemory.csproj" /> | ||
<ProjectReference Include="..\..\source\TransactionalBox.InboxWorker.Storage.InMemory\TransactionalBox.InboxWorker.Storage.InMemory.csproj" /> | ||
<ProjectReference Include="..\..\source\TransactionalBox.InboxWorker.Transport.InMemory\TransactionalBox.InboxWorker.Transport.InMemory.csproj" /> | ||
<ProjectReference Include="..\..\source\TransactionalBox.Outbox.Storage.InMemory\TransactionalBox.Outbox.Storage.InMemory.csproj" /> | ||
<ProjectReference Include="..\..\source\TransactionalBox.OutboxWorker.Storage.InMemory\TransactionalBox.OutboxWorker.Storage.InMemory.csproj" /> | ||
<ProjectReference Include="..\..\source\TransactionalBox.OutboxWorker.Transport.InMemory\TransactionalBox.OutboxWorker.Transport.InMemory.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
8 changes: 8 additions & 0 deletions
8
samples/TransactionalBox.Sample.WebApi.InMemory/appsettings.Development.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft.AspNetCore": "Warning" | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
samples/TransactionalBox.Sample.WebApi.InMemory/appsettings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft.AspNetCore": "Warning" | ||
} | ||
}, | ||
"AllowedHosts": "*" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.