Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ardalis committed Dec 2, 2021
2 parents 833dc3b + 3a81dcf commit a675f3a
Show file tree
Hide file tree
Showing 12 changed files with 43 additions and 24 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ The **eShopOnWeb** sample is related to the [eShopOnContainers](https://github.c
The goal for this sample is to demonstrate some of the principles and patterns described in the [eBook](https://aka.ms/webappebook). It is not meant to be an eCommerce reference application, and as such it does not implement many features that would be obvious and/or essential to a real eCommerce application.

> ### VERSIONS
> #### The `master` branch is currently running ASP.NET Core 5.0.
> #### The `master` branch is currently running ASP.NET Core 6.0.
> #### Older versions are tagged.
## Topics (eBook TOC)
Expand Down
9 changes: 4 additions & 5 deletions src/BlazorAdmin/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Net.Http;
using System.Threading.Tasks;
using BlazorAdmin.Services;
Expand All @@ -20,9 +20,8 @@ public static async Task Main(string[] args)
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("#admin");

var baseUrlConfig = new BaseUrlConfiguration();
builder.Configuration.Bind(BaseUrlConfiguration.CONFIG_NAME, baseUrlConfig);
builder.Services.AddScoped<BaseUrlConfiguration>(sp => baseUrlConfig);
var configSection = builder.Configuration.GetRequiredSection(BaseUrlConfiguration.CONFIG_NAME);
builder.Services.Configure<BaseUrlConfiguration>(configSection);

builder.Services.AddScoped(sp => new HttpClient() { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });

Expand All @@ -37,7 +36,7 @@ public static async Task Main(string[] args)

builder.Services.AddBlazorServices();

builder.Logging.AddConfiguration(builder.Configuration.GetSection("Logging"));
builder.Logging.AddConfiguration(builder.Configuration.GetRequiredSection("Logging"));

await ClearLocalStorageCache(builder.Services);

Expand Down
5 changes: 3 additions & 2 deletions src/BlazorAdmin/Services/CatalogLookupDataService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using BlazorShared.Interfaces;
using BlazorShared.Models;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;

namespace BlazorAdmin.Services;

Expand All @@ -23,12 +24,12 @@ public class CatalogLookupDataService<TLookupData, TReponse>
private readonly string _apiUrl;

public CatalogLookupDataService(HttpClient httpClient,
BaseUrlConfiguration baseUrlConfiguration,
IOptions<BaseUrlConfiguration> baseUrlConfiguration,
ILogger<CatalogLookupDataService<TLookupData, TReponse>> logger)
{
_httpClient = httpClient;
_logger = logger;
_apiUrl = baseUrlConfiguration.ApiBase;
_apiUrl = baseUrlConfiguration.Value.ApiBase;
}

public async Task<List<TLookupData>> List()
Expand Down
5 changes: 3 additions & 2 deletions src/BlazorAdmin/Services/HttpService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Threading.Tasks;
using BlazorShared;
using BlazorShared.Models;
using Microsoft.Extensions.Options;

namespace BlazorAdmin.Services;

Expand All @@ -14,11 +15,11 @@ public class HttpService
private readonly string _apiUrl;


public HttpService(HttpClient httpClient, BaseUrlConfiguration baseUrlConfiguration, ToastService toastService)
public HttpService(HttpClient httpClient, IOptions<BaseUrlConfiguration> baseUrlConfiguration, ToastService toastService)
{
_httpClient = httpClient;
_toastService = toastService;
_apiUrl = baseUrlConfiguration.ApiBase;
_apiUrl = baseUrlConfiguration.Value.ApiBase;
}

public async Task<T> HttpGet<T>(string uri)
Expand Down
2 changes: 1 addition & 1 deletion src/BlazorShared/BlazorShared.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<ItemGroup>
<PackageReference Include="BlazorInputFile" Version="0.2.0" />
<PackageReference Include="FluentValidation" Version="10.3.4" />
<PackageReference Include="FluentValidation" Version="10.3.5" />
</ItemGroup>

</Project>
4 changes: 2 additions & 2 deletions src/PublicApi/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM mcr.microsoft.com/dotnet/aspnet:5.0-buster-slim AS base
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:5.0-buster-slim AS build
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /app
COPY . .
#COPY ["src/PublicApi/PublicApi.csproj", "./PublicApi/"]
Expand Down
2 changes: 1 addition & 1 deletion src/PublicApi/PublicApi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.11.1" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.14.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="6.0.0" />

<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.14.1" />
Expand Down
7 changes: 4 additions & 3 deletions src/PublicApi/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;
using System.Text;
using AutoMapper;
using BlazorShared;
Expand Down Expand Up @@ -96,8 +96,9 @@ public void ConfigureServices(IServiceCollection services)
services.AddScoped(typeof(IAppLogger<>), typeof(LoggerAdapter<>));
services.AddScoped<ITokenClaimsService, IdentityTokenClaimService>();

var baseUrlConfig = new BaseUrlConfiguration();
Configuration.Bind(BaseUrlConfiguration.CONFIG_NAME, baseUrlConfig);
var configSection = Configuration.GetRequiredSection(BaseUrlConfiguration.CONFIG_NAME);
services.Configure<BaseUrlConfiguration>(configSection);
var baseUrlConfig = configSection.Get<BaseUrlConfiguration>();

services.AddMemoryCache();

Expand Down
4 changes: 2 additions & 2 deletions src/Web/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#
# RUN COMMAND
# docker run --name eshopweb --rm -it -p 5106:5106 web
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /app

COPY *.sln .
Expand All @@ -17,7 +17,7 @@ RUN dotnet restore

RUN dotnet publish -c Release -o out

FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS runtime
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS runtime
WORKDIR /app
COPY --from=build /app/src/Web/out ./

Expand Down
5 changes: 3 additions & 2 deletions src/Web/HealthChecks/ApiHealthCheck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@
using System.Threading.Tasks;
using BlazorShared;
using Microsoft.Extensions.Diagnostics.HealthChecks;
using Microsoft.Extensions.Options;

namespace Microsoft.eShopWeb.Web.HealthChecks;

public class ApiHealthCheck : IHealthCheck
{
private readonly BaseUrlConfiguration _baseUrlConfiguration;

public ApiHealthCheck(BaseUrlConfiguration baseUrlConfiguration)
public ApiHealthCheck(IOptions<BaseUrlConfiguration> baseUrlConfiguration)
{
_baseUrlConfiguration = baseUrlConfiguration;
_baseUrlConfiguration = baseUrlConfiguration.Value;
}

public async Task<HealthCheckResult> CheckHealthAsync(
Expand Down
6 changes: 3 additions & 3 deletions src/Web/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,10 @@ public void ConfigureServices(IServiceCollection services)
config.Path = "/allservices";
});

var configSection = Configuration.GetRequiredSection(BaseUrlConfiguration.CONFIG_NAME);
services.Configure<BaseUrlConfiguration>(configSection);
var baseUrlConfig = configSection.Get<BaseUrlConfiguration>();

var baseUrlConfig = new BaseUrlConfiguration();
Configuration.Bind(BaseUrlConfiguration.CONFIG_NAME, baseUrlConfig);
services.AddScoped<BaseUrlConfiguration>(sp => baseUrlConfig);
// Blazor Admin Required Services for Prerendering
services.AddScoped<HttpClient>(s => new HttpClient
{
Expand Down
16 changes: 16 additions & 0 deletions src/Web/key-768c1632-cf7b-41a9-bb7a-bff228ae8fba.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<key id="768c1632-cf7b-41a9-bb7a-bff228ae8fba" version="1">
<creationDate>2021-12-01T14:37:52.0438755Z</creationDate>
<activationDate>2021-12-01T14:37:52.0246578Z</activationDate>
<expirationDate>2022-03-01T14:37:52.0246578Z</expirationDate>
<descriptor deserializerType="Microsoft.AspNetCore.DataProtection.AuthenticatedEncryption.ConfigurationModel.AuthenticatedEncryptorDescriptorDeserializer, Microsoft.AspNetCore.DataProtection, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60">
<descriptor>
<encryption algorithm="AES_256_CBC" />
<validation algorithm="HMACSHA256" />
<masterKey p4:requiresEncryption="true" xmlns:p4="http://schemas.asp.net/2015/03/dataProtection">
<!-- Warning: the key below is in an unencrypted form. -->
<value>PF3GdfO7PnvHYvXyD5nxmoQ91pY9qfA0rjRsdXHdUQbE1Mg9Xok2gXLY2zn8XemsySH37UGrGknht8u/PlehWg==</value>
</masterKey>
</descriptor>
</descriptor>
</key>

0 comments on commit a675f3a

Please sign in to comment.