Skip to content

Commit 0fe6368

Browse files
authored
Merge pull request #118 from litenova/add-dotnet-code-examples
Add DotNet Core examples
2 parents b3ec15b + ad954a7 commit 0fe6368

36 files changed

+420
-67
lines changed

LiteBus.sln

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LiteBus.Commands.Extensions
8585
EndProject
8686
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{CD9293D6-A01C-42A1-9E08-29D2E59B837A}"
8787
EndProject
88-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LiteBus.Samples.Inbox", "samples\LiteBus.Samples.Inbox\LiteBus.Samples.Inbox.csproj", "{4838A90D-F7EE-4CEB-A023-94B923BDECBA}"
88+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LiteBus.Samples.NetCore", "samples\LiteBus.Samples.NetCore\LiteBus.Samples.NetCore.csproj", "{4838A90D-F7EE-4CEB-A023-94B923BDECBA}"
8989
EndProject
9090
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LiteBus.Runtime.Extensions.Autofac", "src\LiteBus.Runtime.Extensions.Autofac\LiteBus.Runtime.Extensions.Autofac.csproj", "{DD74E8C3-B7D5-44DD-8546-17C4C130CB48}"
9191
EndProject
@@ -101,6 +101,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LiteBus.Extensions.Autofac.
101101
EndProject
102102
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LiteBus.Runtime.Abstractions", "src\LiteBus.Runtime.Abstractions\LiteBus.Runtime.Abstractions.csproj", "{F4B10812-2D5E-4017-B5B7-C51A6E9D2C23}"
103103
EndProject
104+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LiteBus.Samples", "samples\LiteBus.Samples\LiteBus.Samples.csproj", "{3AD49E39-402A-4FF0-9A38-96D69A1B94BD}"
105+
EndProject
104106
Global
105107
GlobalSection(SolutionConfigurationPlatforms) = preSolution
106108
Debug|Any CPU = Debug|Any CPU
@@ -139,6 +141,7 @@ Global
139141
{D7980BEC-7B81-4F54-B6B3-B683349E4D6A} = {0C972F3F-001F-41B5-9DE5-6F70DBDC342D}
140142
{0F024130-597C-46FB-8EA3-92E73C2E90E7} = {0EFE2493-E2D3-499C-BB05-B9794298273D}
141143
{F4B10812-2D5E-4017-B5B7-C51A6E9D2C23} = {0C972F3F-001F-41B5-9DE5-6F70DBDC342D}
144+
{3AD49E39-402A-4FF0-9A38-96D69A1B94BD} = {CD9293D6-A01C-42A1-9E08-29D2E59B837A}
142145
EndGlobalSection
143146
GlobalSection(ProjectConfigurationPlatforms) = postSolution
144147
{B1FDAB62-C743-4D41-A8F6-727FEFCA882D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
@@ -261,5 +264,9 @@ Global
261264
{F4B10812-2D5E-4017-B5B7-C51A6E9D2C23}.Debug|Any CPU.Build.0 = Debug|Any CPU
262265
{F4B10812-2D5E-4017-B5B7-C51A6E9D2C23}.Release|Any CPU.ActiveCfg = Release|Any CPU
263266
{F4B10812-2D5E-4017-B5B7-C51A6E9D2C23}.Release|Any CPU.Build.0 = Release|Any CPU
267+
{3AD49E39-402A-4FF0-9A38-96D69A1B94BD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
268+
{3AD49E39-402A-4FF0-9A38-96D69A1B94BD}.Debug|Any CPU.Build.0 = Debug|Any CPU
269+
{3AD49E39-402A-4FF0-9A38-96D69A1B94BD}.Release|Any CPU.ActiveCfg = Release|Any CPU
270+
{3AD49E39-402A-4FF0-9A38-96D69A1B94BD}.Release|Any CPU.Build.0 = Release|Any CPU
264271
EndGlobalSection
265272
EndGlobal

samples/LiteBus.Samples.Inbox/Controllers/WeatherForecastController.cs

Lines changed: 0 additions & 32 deletions
This file was deleted.

samples/LiteBus.Samples.Inbox/LiteBus.Samples.Inbox.csproj

Lines changed: 0 additions & 13 deletions
This file was deleted.

samples/LiteBus.Samples.Inbox/LiteBus.Samples.Inbox.http

Lines changed: 0 additions & 6 deletions
This file was deleted.

samples/LiteBus.Samples.Inbox/WeatherForecast.cs

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
using LiteBus.Commands.Abstractions;
2+
using LiteBus.Queries.Abstractions;
3+
using LiteBus.Samples.Commands;
4+
using LiteBus.Samples.Queries;
5+
using LiteBus.Samples.Requests;
6+
using Microsoft.AspNetCore.Mvc;
7+
8+
namespace LiteBus.Samples.NetCore.Controllers;
9+
10+
[ApiController]
11+
[Route("api/[controller]")]
12+
public sealed class OrdersController : ControllerBase
13+
{
14+
private readonly ICommandMediator _commandMediator;
15+
private readonly IQueryMediator _queryMediator;
16+
17+
public OrdersController(ICommandMediator commandMediator, IQueryMediator queryMediator)
18+
{
19+
_commandMediator = commandMediator;
20+
_queryMediator = queryMediator;
21+
}
22+
23+
[HttpPost]
24+
[ProducesResponseType(typeof(Guid), StatusCodes.Status201Created)]
25+
public async Task<IActionResult> CreateOrder(
26+
[FromBody] PlaceOrderRequest request,
27+
CancellationToken cancellationToken)
28+
{
29+
var command = new PlaceOrderCommand(
30+
request.CustomerId,
31+
request.LineItems.Select(x =>
32+
new PlaceOrderLineItemDto(x.ProductId, x.Quantity, x.UnitPrice)).ToList());
33+
34+
var orderId = await _commandMediator.SendAsync(command, cancellationToken);
35+
return CreatedAtAction(nameof(GetOrderById), new { id = orderId }, orderId);
36+
}
37+
38+
[HttpPost("{orderId:guid}/confirm")]
39+
[ProducesResponseType(StatusCodes.Status204NoContent)]
40+
[ProducesResponseType(StatusCodes.Status404NotFound)]
41+
public async Task<IActionResult> ConfirmOrder(Guid orderId, CancellationToken cancellationToken)
42+
{
43+
var command = new ConfirmOrderCommand(orderId);
44+
await _commandMediator.SendAsync(command, cancellationToken);
45+
return NoContent();
46+
}
47+
48+
[HttpGet("{id:guid}")]
49+
[ProducesResponseType(typeof(OrderDto), StatusCodes.Status200OK)]
50+
[ProducesResponseType(StatusCodes.Status404NotFound)]
51+
public async Task<IActionResult> GetOrderById(Guid id, CancellationToken cancellationToken)
52+
{
53+
var query = new GetOrderByIdQuery(id);
54+
var result = await _queryMediator.QueryAsync(query, cancellationToken);
55+
return result == null ? NotFound() : Ok(result);
56+
}
57+
58+
[HttpGet("customer/{customerId}")]
59+
[ProducesResponseType(typeof(IEnumerable<OrderDto>), StatusCodes.Status200OK)]
60+
public async Task<IActionResult> GetOrdersByCustomer(string customerId, CancellationToken cancellationToken)
61+
{
62+
var query = new GetOrdersByCustomerQuery(customerId);
63+
var results = await _queryMediator.QueryAsync(query, cancellationToken);
64+
return Ok(results);
65+
}
66+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net9.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.10" />
11+
<PackageReference Include="NSwag.AspNetCore" Version="14.6.1" />
12+
</ItemGroup>
13+
14+
<ItemGroup>
15+
<ProjectReference Include="..\LiteBus.Samples\LiteBus.Samples.csproj" />
16+
<ProjectReference Include="..\..\src\LiteBus.Commands.Extensions.Microsoft.DependencyInjection\LiteBus.Commands.Extensions.Microsoft.DependencyInjection.csproj"/>
17+
<ProjectReference Include="..\..\src\LiteBus.Queries.Extensions.Microsoft.DependencyInjection\LiteBus.Queries.Extensions.Microsoft.DependencyInjection.csproj"/>
18+
<ProjectReference Include="..\..\src\LiteBus.Events.Extensions.Microsoft.DependencyInjection\LiteBus.Events.Extensions.Microsoft.DependencyInjection.csproj"/>
19+
20+
</ItemGroup>
21+
22+
</Project>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Microsoft Visual Studio Solution File, Format Version 12.00
2+
# Visual Studio Version 17
3+
VisualStudioVersion = 17.5.2.0
4+
MinimumVisualStudioVersion = 10.0.40219.1
5+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LiteBus.Samples.NetCore", "LiteBus.Samples.NetCore.csproj", "{1D15B684-9F43-A5D8-C670-7E25C5CF4909}"
6+
EndProject
7+
Global
8+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
9+
Debug|Any CPU = Debug|Any CPU
10+
Release|Any CPU = Release|Any CPU
11+
EndGlobalSection
12+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
13+
{1D15B684-9F43-A5D8-C670-7E25C5CF4909}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
14+
{1D15B684-9F43-A5D8-C670-7E25C5CF4909}.Debug|Any CPU.Build.0 = Debug|Any CPU
15+
{1D15B684-9F43-A5D8-C670-7E25C5CF4909}.Release|Any CPU.ActiveCfg = Release|Any CPU
16+
{1D15B684-9F43-A5D8-C670-7E25C5CF4909}.Release|Any CPU.Build.0 = Release|Any CPU
17+
EndGlobalSection
18+
GlobalSection(SolutionProperties) = preSolution
19+
HideSolutionNode = FALSE
20+
EndGlobalSection
21+
GlobalSection(ExtensibilityGlobals) = postSolution
22+
SolutionGuid = {E4F687D0-6DA4-4224-B188-9252B98DEFCF}
23+
EndGlobalSection
24+
EndGlobal

samples/LiteBus.Samples.Inbox/Program.cs renamed to samples/LiteBus.Samples.NetCore/Program.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
1+
using LiteBus.Samples.NetCore;
2+
13
var builder = WebApplication.CreateBuilder(args);
24

35
// Add services to the container.
46

57
builder.Services.AddControllers();
68

79
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
8-
builder.Services.AddOpenApi();
9-
10+
builder.Services.AddOpenApiDocument();
11+
builder.Services.AddLiteBusExample();
1012
var app = builder.Build();
1113

1214
// Configure the HTTP request pipeline.
1315
if (app.Environment.IsDevelopment())
1416
{
15-
app.MapOpenApi();
17+
app.UseSwaggerUi();
18+
app.UseOpenApi();
1619
}
1720

1821
app.UseHttpsRedirection();

samples/LiteBus.Samples.Inbox/Properties/launchSettings.json renamed to samples/LiteBus.Samples.NetCore/Properties/launchSettings.json

File renamed without changes.

0 commit comments

Comments
 (0)