Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Ordering projects migration to net 5 #1550

Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,24 @@ namespace Microsoft.eShopOnContainers.Mobile.Shopping.HttpAggregator.Services
{
public class OrderingService : IOrderingService
{
private readonly HttpClient _httpClient;
private readonly UrlsConfig _urls;
private readonly OrderingGrpc.OrderingGrpcClient _orderingGrpcClient;
private readonly ILogger<OrderingService> _logger;

public OrderingService(HttpClient httpClient, IOptions<UrlsConfig> config, ILogger<OrderingService> logger)
public OrderingService(OrderingGrpc.OrderingGrpcClient orderingGrpcClient, ILogger<OrderingService> logger)
{
_httpClient = httpClient;
_urls = config.Value;
_orderingGrpcClient = orderingGrpcClient;
_logger = logger;
}

public async Task<OrderData> GetOrderDraftAsync(BasketData basketData)
{
_logger.LogDebug(" grpc client created, basketData={@basketData}", basketData);

return await GrpcCallerService.CallService(_urls.GrpcOrdering, async channel =>
{
var client = new OrderingGrpc.OrderingGrpcClient(channel);
_logger.LogDebug(" grpc client created, basketData={@basketData}", basketData);

var command = MapToOrderDraftCommand(basketData);
var response = await client.CreateOrderDraftFromBasketDataAsync(command);
_logger.LogDebug(" grpc response: {@response}", response);
var command = MapToOrderDraftCommand(basketData);
var response = await _orderingGrpcClient.CreateOrderDraftFromBasketDataAsync(command);
_logger.LogDebug(" grpc response: {@response}", response);

return MapToResponse(response, basketData);
});
return MapToResponse(response, basketData);
}

private OrderData MapToResponse(GrpcOrdering.OrderDraftDTO orderDraft, BasketData basketData)
Expand Down
12 changes: 9 additions & 3 deletions src/ApiGateways/Mobile.Bff.Shopping/aggregator/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using CatalogApi;
using Devspaces.Support;
using GrpcBasket;
using GrpcOrdering;
using HealthChecks.UI.Client;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Builder;
Expand Down Expand Up @@ -185,9 +186,6 @@ public static IServiceCollection AddHttpServices(this IServiceCollection service
services.AddHttpClient<IOrderApiClient, OrderApiClient>()
.AddDevspacesSupport();

services.AddHttpClient<IOrderingService, OrderingService>()
.AddDevspacesSupport();

return services;
}

Expand All @@ -211,6 +209,14 @@ public static IServiceCollection AddGrpcServices(this IServiceCollection service
options.Address = new Uri(catalogApi);
}).AddInterceptor<GrpcExceptionInterceptor>();

services.AddScoped<IOrderingService, OrderingService>();

services.AddGrpcClient<OrderingGrpc.OrderingGrpcClient>((services, options) =>
{
var orderingApi = services.GetRequiredService<IOptions<UrlsConfig>>().Value.GrpcOrdering;
options.Address = new Uri(orderingApi);
}).AddInterceptor<GrpcExceptionInterceptor>();

return services;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using GrpcOrdering;
using Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Config;
using Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Models;
using Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using System.Linq;
Expand All @@ -11,30 +11,24 @@ namespace Microsoft.eShopOnContainers.Web.Shopping.HttpAggregator.Services
{
public class OrderingService : IOrderingService
{
private readonly UrlsConfig _urls;
private readonly OrderingGrpc.OrderingGrpcClient _orderingGrpcClient;
private readonly ILogger<OrderingService> _logger;
public readonly HttpClient _httpClient;

public OrderingService(HttpClient httpClient, IOptions<UrlsConfig> config, ILogger<OrderingService> logger)
public OrderingService(OrderingGrpc.OrderingGrpcClient orderingGrpcClient, ILogger<OrderingService> logger)
{
_urls = config.Value;
_httpClient = httpClient;
_orderingGrpcClient = orderingGrpcClient;
_logger = logger;
}

public async Task<OrderData> GetOrderDraftAsync(BasketData basketData)
{
return await GrpcCallerService.CallService(_urls.GrpcOrdering, async channel =>
{
var client = new OrderingGrpc.OrderingGrpcClient(channel);
_logger.LogDebug(" grpc client created, basketData={@basketData}", basketData);
_logger.LogDebug(" grpc client created, basketData={@basketData}", basketData);

var command = MapToOrderDraftCommand(basketData);
var response = await client.CreateOrderDraftFromBasketDataAsync(command);
_logger.LogDebug(" grpc response: {@response}", response);
var command = MapToOrderDraftCommand(basketData);
var response = await _orderingGrpcClient.CreateOrderDraftFromBasketDataAsync(command);
_logger.LogDebug(" grpc response: {@response}", response);

return MapToResponse(response, basketData);
});
return MapToResponse(response, basketData);
}

private OrderData MapToResponse(GrpcOrdering.OrderDraftDTO orderDraft, BasketData basketData)
Expand Down
13 changes: 9 additions & 4 deletions src/ApiGateways/Web.Bff.Shopping/aggregator/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using CatalogApi;
using Devspaces.Support;
using GrpcBasket;
using GrpcOrdering;
using HealthChecks.UI.Client;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Builder;
Expand Down Expand Up @@ -189,10 +190,6 @@ public static IServiceCollection AddApplicationServices(this IServiceCollection
.AddHttpMessageHandler<HttpClientAuthorizationDelegatingHandler>()
.AddDevspacesSupport();

services.AddHttpClient<IOrderingService, OrderingService>()
.AddHttpMessageHandler<HttpClientAuthorizationDelegatingHandler>()
.AddDevspacesSupport();

return services;
}

Expand All @@ -216,6 +213,14 @@ public static IServiceCollection AddGrpcServices(this IServiceCollection service
options.Address = new Uri(catalogApi);
}).AddInterceptor<GrpcExceptionInterceptor>();

services.AddScoped<IOrderingService, OrderingService>();

services.AddGrpcClient<OrderingGrpc.OrderingGrpcClient>((services, options) =>
{
var orderingApi = services.GetRequiredService<IOptions<UrlsConfig>>().Value.GrpcOrdering;
options.Address = new Uri(orderingApi);
}).AddInterceptor<GrpcExceptionInterceptor>();

return services;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,19 @@ public CreateOrderCommand(List<BasketItem> basketItems, string userId, string us
}


public class OrderItemDTO
public record OrderItemDTO
{
public int ProductId { get; set; }
public int ProductId { get; init; }

public string ProductName { get; set; }
public string ProductName { get; init; }

public decimal UnitPrice { get; set; }
public decimal UnitPrice { get; init; }

public decimal Discount { get; set; }
public decimal Discount { get; init; }

public int Units { get; set; }
public int Units { get; init; }

public string PictureUrl { get; set; }
public string PictureUrl { get; init; }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using global::Ordering.API.Application.Models;
using MediatR;
using Microsoft.eShopOnContainers.Services.Ordering.API.Infrastructure.Services;
using Microsoft.eShopOnContainers.Services.Ordering.Infrastructure.Idempotency;
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -42,10 +41,10 @@ public Task<OrderDraftDTO> Handle(CreateOrderDraftCommand message, CancellationT
}


public class OrderDraftDTO
public record OrderDraftDTO
{
public IEnumerable<OrderItemDTO> OrderItems { get; set; }
public decimal Total { get; set; }
public IEnumerable<OrderItemDTO> OrderItems { get; init; }
public decimal Total { get; init; }

public static OrderDraftDTO FromOrder(Order order)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ namespace Ordering.API.Application.Models
{
public class BasketItem
{
public string Id { get; set; }
public int ProductId { get; set; }
public string ProductName { get; set; }
public decimal UnitPrice { get; set; }
public decimal OldUnitPrice { get; set; }
public int Quantity { get; set; }
public string PictureUrl { get; set; }
public string Id { get; init; }
public int ProductId { get; init; }
public string ProductName { get; init; }
public decimal UnitPrice { get; init; }
public decimal OldUnitPrice { get; init; }
public int Quantity { get; init; }
public string PictureUrl { get; init; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,39 @@

namespace Microsoft.eShopOnContainers.Services.Ordering.API.Application.Queries
{
public class Orderitem
public record Orderitem
{
public string productname { get; set; }
public int units { get; set; }
public double unitprice { get; set; }
public string pictureurl { get; set; }
public string productname { get; init; }
public int units { get; init; }
public double unitprice { get; init; }
public string pictureurl { get; init; }
}

public class Order
public record Order
{
public int ordernumber { get; set; }
public DateTime date { get; set; }
public string status { get; set; }
public string description { get; set; }
public string street { get; set; }
public string city { get; set; }
public string zipcode { get; set; }
public string country { get; set; }
public int ordernumber { get; init; }
public DateTime date { get; init; }
public string status { get; init; }
public string description { get; init; }
public string street { get; init; }
public string city { get; init; }
public string zipcode { get; init; }
public string country { get; init; }
public List<Orderitem> orderitems { get; set; }
public decimal total { get; set; }
}

public class OrderSummary
public record OrderSummary
{
public int ordernumber { get; set; }
public DateTime date { get; set; }
public string status { get; set; }
public double total { get; set; }
public int ordernumber { get; init; }
public DateTime date { get; init; }
public string status { get; init; }
public double total { get; init; }
}

public class CardType
public record CardType
{
public int Id { get; set; }
public string Name { get; set; }
public int Id { get; init; }
public string Name { get; init; }
}
}
4 changes: 2 additions & 2 deletions src/Services/Ordering/Ordering.API/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1 AS base
FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
WORKDIR /app
EXPOSE 80

FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
WORKDIR /src

# It's important to keep lines from here down to "COPY . ." identical in all Dockerfiles
Expand Down
48 changes: 24 additions & 24 deletions src/Services/Ordering/Ordering.API/Ordering.API.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net5.0</TargetFramework>
<UserSecretsId>aspnet-Ordering.API-20161122013547</UserSecretsId>
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback>
<DockerComposeProjectPath>..\..\..\..\docker-compose.dcproj</DockerComposeProjectPath>
Expand Down Expand Up @@ -37,36 +37,36 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="AspNetCore.HealthChecks.AzureServiceBus" Version="3.0.0" />
<PackageReference Include="AspNetCore.HealthChecks.Rabbitmq" Version="3.0.3" />
<PackageReference Include="AspNetCore.HealthChecks.SqlServer" Version="3.0.0" />
<PackageReference Include="AspNetCore.HealthChecks.UI.Client" Version="3.0.0" />
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="5.0.1" />
<PackageReference Include="Dapper" Version="2.0.30" />
<PackageReference Include="FluentValidation.AspNetCore" Version="8.6.0" />
<PackageReference Include="Google.Protobuf" Version="3.11.2" />
<PackageReference Include="Grpc.AspNetCore.Server" Version="2.25.0" />
<PackageReference Include="Grpc.Tools" Version="2.25.0" PrivateAssets="All" />
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="7.0.0" />
<PackageReference Include="MediatR" Version="7.0.0" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.12.0" />
<PackageReference Include="Microsoft.ApplicationInsights.DependencyCollector" Version="2.12.0" />
<PackageReference Include="Microsoft.ApplicationInsights.Kubernetes" Version="1.1.1" />
<PackageReference Include="AspNetCore.HealthChecks.AzureServiceBus" Version="3.2.2" />
<PackageReference Include="AspNetCore.HealthChecks.Rabbitmq" Version="3.1.4" />
<PackageReference Include="AspNetCore.HealthChecks.SqlServer" Version="3.2.0" />
<PackageReference Include="AspNetCore.HealthChecks.UI.Client" Version="3.1.2" />
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="7.1.0" />
<PackageReference Include="Dapper" Version="2.0.78" />
<PackageReference Include="FluentValidation.AspNetCore" Version="9.3.0" />
<PackageReference Include="Google.Protobuf" Version="3.14.0" />
<PackageReference Include="Grpc.AspNetCore.Server" Version="2.34.0" />
<PackageReference Include="Grpc.Tools" Version="2.34.0" PrivateAssets="All" />
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="9.0.0" />
<PackageReference Include="MediatR" Version="9.0.0" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.16.0" />
<PackageReference Include="Microsoft.ApplicationInsights.DependencyCollector" Version="2.16.0" />
<PackageReference Include="Microsoft.ApplicationInsights.Kubernetes" Version="1.1.3" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.HealthChecks" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.HealthChecks" Version="1.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.AzureKeyVault" Version="3.1.0" />
<PackageReference Include="Microsoft.Extensions.Logging.AzureAppServices" Version="3.1.0" />
<PackageReference Include="Microsoft.NETCore.Platforms" Version="3.1.0" />
<PackageReference Include="Polly" Version="7.2.0" />
<PackageReference Include="Serilog.AspNetCore" Version="3.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="5.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.AzureKeyVault" Version="3.1.10" />
<PackageReference Include="Microsoft.Extensions.Logging.AzureAppServices" Version="5.0.1" />
<PackageReference Include="Microsoft.NETCore.Platforms" Version="5.0.0" />
<PackageReference Include="Polly" Version="7.2.1" />
<PackageReference Include="Serilog.AspNetCore" Version="3.4.0" />
<PackageReference Include="Serilog.Enrichers.Environment" Version="2.1.3" />
<PackageReference Include="Serilog.Settings.Configuration" Version="3.1.1-dev-00216" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.0.0-dev-00834" />
<PackageReference Include="Serilog.Sinks.Http" Version="5.2.0" />
<PackageReference Include="Serilog.Sinks.Http" Version="7.2.0" />
<PackageReference Include="Serilog.Sinks.Seq" Version="4.1.0-dev-00166" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.0.0-rc5" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.6.3" />
<PackageReference Include="System.Reflection" Version="4.4.0-beta-24913-02" />
<PackageReference Include="System.ValueTuple" Version="4.6.0-preview1-26829-04" />
</ItemGroup>
Expand Down
Loading