-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from Applicita/v2
V2
- Loading branch information
Showing
48 changed files
with
716 additions
and
568 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
Binary file modified
BIN
-2.5 KB
(98%)
img/Example-service-client-within-and-across-microservices.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
@@ -1,6 +1,30 @@ | ||
Param( | ||
Param( | ||
[Parameter(Mandatory, HelpMessage="The name (without 'Service' suffix) of the logical service to add to the CoreTeam multiservice solution in the current directory; used in the name of the new service project and in new namespaces + classes in the Apis and Contracts projects")] | ||
[string] | ||
$Name | ||
) | ||
dotnet new mcs-orleans-multiservice --RootNamespace Applicita.eShop -M . --Logicalservice $Name --allow-scripts Yes | ||
|
||
# Function to update the Program.cs file to add a new parameter to the RegisterEndpoints method | ||
function Update-RegisterEndpoints { | ||
$newParameter = "`n typeof(Applicita.eShop.Apis.${Name}Api.${Name}Endpoints)`n" | ||
$apisDirectory = Join-Path -Path $PWD -ChildPath "Apis" | ||
$programFile = Get-ChildItem -Path $apisDirectory -Recurse -Filter "Program.cs" -ErrorAction SilentlyContinue | Select-Object -First 1 | ||
|
||
if ($programFile -ne $null) { | ||
$programContent = Get-Content -Path $programFile.FullName -Raw | ||
$pattern = "(?s)(app\s*\.RegisterEndpoints\s*\(.+?\))\s*\)" | ||
$modifiedContent = $programContent -replace $pattern, "`$1,$newParameter)" | ||
|
||
if ($modifiedContent -ne $programContent) { | ||
Set-Content -Path $programFile.FullName -Value $modifiedContent | ||
Write-Output "Successfully added new parameter to RegisterEndpoints call in $($programFile.FullName):$newParameter" | ||
return | ||
} | ||
} | ||
|
||
Write-Warning "Could not automatically add below parameter to the RegisterEndpoints(...) call; please add it manually:$newParameter" | ||
} | ||
|
||
dotnet new mcs-orleans-multiservice --RootNamespace Applicita.eShop -M . --Logicalservice $Name --allow-scripts Yes | ||
|
||
Update-RegisterEndpoints |
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
48 changes: 0 additions & 48 deletions
48
src/Example/eShopBySingleTeam/TeamA/Apis/CatalogApi/CatalogController.cs
This file was deleted.
Oops, something went wrong.
52 changes: 52 additions & 0 deletions
52
src/Example/eShopBySingleTeam/TeamA/Apis/CatalogApi/CatalogEndpoints.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,52 @@ | ||
using Applicita.eShop.Contracts.CatalogContract; | ||
|
||
namespace Applicita.eShop.Apis.CatalogApi; | ||
|
||
public class CatalogEndpoints(IClusterClient orleans) : IEndpoints | ||
{ | ||
const string Products = "/products"; | ||
const string Product = Products + "/{id}"; | ||
|
||
readonly ICatalogGrain catalog = orleans.GetGrain<ICatalogGrain>(ICatalogGrain.Key); | ||
|
||
public void Register(IEndpointRouteBuilder routeBuilder) | ||
{ | ||
var group = routeBuilder.MapGroup("/catalog").WithTags("Catalog"); | ||
_ = group.MapPost (Products, CreateProduct); | ||
_ = group.MapGet (Products, GetProducts ).WithName(nameof(GetProducts)); | ||
_ = group.MapPut (Products, UpdateProduct); | ||
_ = group.MapDelete(Product , DeleteProduct); | ||
} | ||
|
||
/// <response code="201">The new product is created with the returned id</response> | ||
async Task<CreatedAtRoute<int>> CreateProduct(Product product) | ||
{ | ||
int id = await catalog.CreateProduct(product); | ||
return CreatedAtRoute(id, nameof(GetProducts), new { id }); | ||
} | ||
|
||
/// <response code="200"> | ||
/// Products for all <paramref name="id"/>'s currently in the catalog are returned; | ||
/// unknown product id's are skipped. | ||
/// If no <paramref name="id"/>'s are specified, all products in the catalog are returned | ||
/// </response> | ||
async Task<Ok<ImmutableArray<Product>>> GetProducts(int[]? id) => Ok( | ||
id?.Length > 0 | ||
? await catalog.GetCurrentProducts([.. id]) | ||
: await catalog.GetAllProducts() | ||
); | ||
|
||
/// <response code="200">The product is updated</response> | ||
/// <response code="404">The product id is not found</response> | ||
public async Task<Results<Ok, NotFound<int>>> UpdateProduct(Product product) | ||
=> await catalog.UpdateProduct(product) | ||
? Ok() | ||
: NotFound(product.Id); | ||
|
||
/// <response code="200">The product is deleted</response> | ||
/// <response code="404">The product id is not found</response> | ||
public async Task<Results<Ok, NotFound<int>>> DeleteProduct(int id) | ||
=> await catalog.DeleteProduct(id) | ||
? Ok() | ||
: NotFound(id); | ||
} |
15 changes: 15 additions & 0 deletions
15
src/Example/eShopBySingleTeam/TeamA/Apis/Foundation/Extensions.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,15 @@ | ||
namespace Applicita.eShop.Apis.Foundation; | ||
|
||
public interface IEndpoints | ||
{ | ||
void Register(IEndpointRouteBuilder routeBuilder); | ||
} | ||
|
||
public static class WebApplicationExtensions | ||
{ | ||
public static void RegisterEndpoints(this WebApplication app, params Type[] endpointsTypes) | ||
{ | ||
foreach (var endpointsType in endpointsTypes) | ||
((IEndpoints)ActivatorUtilities.CreateInstance(app.Services, endpointsType)).Register(app); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/Example/eShopBySingleTeam/TeamA/Apis/Foundation/GlobalSuppressions.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,9 @@ | ||
// This file is used by Code Analysis to maintain SuppressMessage | ||
// attributes that are applied to this project. | ||
// Project-level suppressions either have no target or are given | ||
// a specific target and scoped to a namespace, type, member, etc. | ||
|
||
using System.Diagnostics.CodeAnalysis; | ||
|
||
[assembly: SuppressMessage("Reliability", "CA2007:Consider calling ConfigureAwait on the awaited task", Justification = "Not relevant in ASP.NET Core")] | ||
[assembly: SuppressMessage("Design", "CA1062:Validate arguments of public methods", Justification = "Public methods are only invoked by ASP.NET Core, which ensures non-null parameter values")] |
5 changes: 4 additions & 1 deletion
5
src/Example/eShopBySingleTeam/TeamA/Apis/Foundation/GlobalUsings.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 |
---|---|---|
@@ -1 +1,4 @@ | ||
global using Microsoft.AspNetCore.Mvc; | ||
global using System.Collections.Immutable; | ||
global using Microsoft.AspNetCore.Http.HttpResults; | ||
global using static Microsoft.AspNetCore.Http.TypedResults; | ||
global using Applicita.eShop.Apis.Foundation; |
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
38 changes: 20 additions & 18 deletions
38
src/Example/eShopBySingleTeam/TeamA/BasketService/BasketService.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 |
---|---|---|
@@ -1,25 +1,27 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
|
||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors> | ||
<AnalysisLevel>preview-All</AnalysisLevel> | ||
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild> | ||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
|
||
<AssemblyName>Applicita.eShop.$(MSBuildProjectName)</AssemblyName> | ||
<RootNamespace>Applicita.eShop.$(MSBuildProjectName.Replace(" ", "_"))</RootNamespace> | ||
</PropertyGroup> | ||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors> | ||
<AnalysisLevel>preview-All</AnalysisLevel> | ||
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Orleans.Runtime" Version="7.1.0" /> | ||
<PackageReference Include="Microsoft.Orleans.Sdk" Version="7.1.0" /> | ||
</ItemGroup> | ||
<NoWarn>$(NoWarn);EnableGenerateDocumentationFile</NoWarn> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Contracts\Contracts.csproj" /> | ||
</ItemGroup> | ||
<AssemblyName>Applicita.eShop.$(MSBuildProjectName)</AssemblyName> | ||
<RootNamespace>Applicita.eShop.$(MSBuildProjectName.Replace(" ", "_"))</RootNamespace> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Orleans.Runtime" Version="8.0.0" /> | ||
<PackageReference Include="Microsoft.Orleans.Sdk" Version="8.0.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Contracts\Contracts.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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.