Skip to content

Commit a1a9b48

Browse files
committed
Upgrade to ASP.NET Core 3.0
1 parent 26613a8 commit a1a9b48

34 files changed

+315
-255
lines changed

BlazorRouter.Sample/App.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<MainLayout></MainLayout>
1+
<MainLayout />

BlazorRouter.Sample/BlazorRouter.Sample.csproj

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,9 @@
1-
<Project Sdk="Microsoft.NET.Sdk.Web">
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFramework>netstandard2.0</TargetFramework>
5-
<LangVersion>7.3</LangVersion>
6-
<RazorLangVersion>3.0</RazorLangVersion>
4+
<TargetFramework>netcoreapp3.0</TargetFramework>
75
</PropertyGroup>
86

9-
<ItemGroup>
10-
<PackageReference Include="Microsoft.AspNetCore.Blazor" Version="3.0.0-preview8.19405.7" />
11-
<PackageReference Include="Microsoft.AspNetCore.Blazor.HttpClient" Version="3.0.0-preview8.19405.7" />
12-
<PackageReference Include="Microsoft.AspNetCore.Blazor.Build" Version="3.0.0-preview8.19405.7" PrivateAssets="all" />
13-
<PackageReference Include="Microsoft.AspNetCore.Blazor.DevServer" Version="3.0.0-preview8.19405.7" PrivateAssets="all" />
14-
</ItemGroup>
15-
167
<ItemGroup>
178
<ProjectReference Include="..\BlazorRouter\BlazorRouter.csproj" />
189
</ItemGroup>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
3+
namespace BlazorRouter.Sample.Data
4+
{
5+
public class WeatherForecast
6+
{
7+
public DateTime Date { get; set; }
8+
9+
public int TemperatureC { get; set; }
10+
11+
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
12+
13+
public string Summary { get; set; }
14+
}
15+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System;
2+
using System.Linq;
3+
using System.Threading.Tasks;
4+
5+
namespace BlazorRouter.Sample.Data
6+
{
7+
public class WeatherForecastService
8+
{
9+
private static readonly string[] Summaries = new[]
10+
{
11+
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
12+
};
13+
14+
public Task<WeatherForecast[]> GetForecastAsync(DateTime startDate)
15+
{
16+
var rng = new Random();
17+
return Task.FromResult(Enumerable.Range(1, 5).Select(index => new WeatherForecast
18+
{
19+
Date = startDate.AddDays(index),
20+
TemperatureC = rng.Next(-20, 55),
21+
Summary = Summaries[rng.Next(Summaries.Length)]
22+
}).ToArray());
23+
}
24+
}
25+
}

BlazorRouter.Sample/Pages/Counter.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@
2323
}
2424
return Task.CompletedTask;
2525
}
26-
}
26+
}

BlazorRouter.Sample/Pages/Error.razor

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
@page "/error"
2+
3+
4+
<h1 class="text-danger">Error.</h1>
5+
<h2 class="text-danger">An error occurred while processing your request.</h2>
6+
7+
<h3>Development Mode</h3>
8+
<p>
9+
Swapping to <strong>Development</strong> environment will display more detailed information about the error that occurred.
10+
</p>
11+
<p>
12+
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
13+
It can result in displaying sensitive information from exceptions to end users.
14+
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
15+
and restarting the app.
16+
</p>

BlazorRouter.Sample/Pages/FetchData.razor

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
@inject HttpClient Http
1+
@using BlazorRouter.Sample.Data
2+
@inject WeatherForecastService ForecastService
23

34
<h1>Weather forecast</h1>
45

5-
<p>This component demonstrates fetching data from the server.</p>
6+
<p>This component demonstrates fetching data from a service.</p>
67

78
@if (forecasts == null)
89
{
@@ -20,10 +21,9 @@ else
2021
</tr>
2122
</thead>
2223
<tbody>
23-
@for (var i = 0; i < forecasts.Length; i++)
24+
@foreach (var forecast in forecasts)
2425
{
25-
var forecast = forecasts[i];
26-
<tr @key="i">
26+
<tr>
2727
<td>@forecast.Date.ToShortDateString()</td>
2828
<td>@forecast.TemperatureC</td>
2929
<td>@forecast.TemperatureF</td>
@@ -39,17 +39,6 @@ else
3939

4040
protected override async Task OnInitializedAsync()
4141
{
42-
forecasts = await Http.GetJsonAsync<WeatherForecast[]>("sample-data/weather.json");
43-
}
44-
45-
class WeatherForecast
46-
{
47-
public DateTime Date { get; set; }
48-
49-
public int TemperatureC { get; set; }
50-
51-
public int TemperatureF { get; set; }
52-
53-
public string Summary { get; set; }
42+
forecasts = await ForecastService.GetForecastAsync(DateTime.Now);
5443
}
5544
}

BlazorRouter.Sample/Pages/HomePage.razor renamed to BlazorRouter.Sample/Pages/Index.razor

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
Welcome to your new app. You have counted to @CountValue.
44

5-
<SurveyPrompt Title="How is Blazor working for you?" />
6-
75
<br />
86
<NavLink href="counter/500">
97
Click here to count from 500 directly.
@@ -15,4 +13,4 @@ Welcome to your new app. You have counted to @CountValue.
1513

1614
@code {
1715
[Parameter] public int CountValue { get; set; }
18-
}
16+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
@page "/"
2+
@namespace BlazorRouter.Sample.Pages
3+
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
4+
5+
<!DOCTYPE html>
6+
<html lang="en">
7+
<head>
8+
<meta charset="utf-8" />
9+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
10+
<title>BlazorRouter.Sample</title>
11+
<base href="~/" />
12+
<link rel="stylesheet" href="css/bootstrap/bootstrap.min.css" />
13+
<link href="css/site.css" rel="stylesheet" />
14+
</head>
15+
<body>
16+
<app>
17+
@(await Html.RenderComponentAsync<App>(RenderMode.ServerPrerendered))
18+
</app>
19+
20+
<script src="_framework/blazor.server.js"></script>
21+
</body>
22+
</html>

BlazorRouter.Sample/Pages/_Imports.razor

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

BlazorRouter.Sample/Program.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1-
using Microsoft.AspNetCore.Blazor.Hosting;
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using System.Linq;
5+
using System.Threading.Tasks;
6+
using Microsoft.AspNetCore;
7+
using Microsoft.AspNetCore.Hosting;
8+
using Microsoft.Extensions.Configuration;
9+
using Microsoft.Extensions.Hosting;
10+
using Microsoft.Extensions.Logging;
211

312
namespace BlazorRouter.Sample
413
{
@@ -9,8 +18,11 @@ public static void Main(string[] args)
918
CreateHostBuilder(args).Build().Run();
1019
}
1120

12-
public static IWebAssemblyHostBuilder CreateHostBuilder(string[] args) =>
13-
BlazorWebAssemblyHost.CreateDefaultBuilder()
14-
.UseBlazorStartup<Startup>();
21+
public static IHostBuilder CreateHostBuilder(string[] args) =>
22+
Host.CreateDefaultBuilder(args)
23+
.ConfigureWebHostDefaults(webBuilder =>
24+
{
25+
webBuilder.UseStartup<Startup>();
26+
});
1527
}
1628
}

BlazorRouter.Sample/Properties/launchSettings.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"windowsAuthentication": false,
44
"anonymousAuthentication": true,
55
"iisExpress": {
6-
"applicationUrl": "http://localhost:52666/",
7-
"sslPort": 0
6+
"applicationUrl": "http://localhost:33502",
7+
"sslPort": 44361
88
}
99
},
1010
"profiles": {
@@ -18,10 +18,10 @@
1818
"BlazorRouter.Sample": {
1919
"commandName": "Project",
2020
"launchBrowser": true,
21+
"applicationUrl": "https://localhost:5001;http://localhost:5000",
2122
"environmentVariables": {
2223
"ASPNETCORE_ENVIRONMENT": "Development"
23-
},
24-
"applicationUrl": "http://localhost:52667/"
24+
}
2525
}
2626
}
27-
}
27+
}

BlazorRouter.Sample/Shared/MainLayout.razor

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
1-
<div class="sidebar">
1+
@inherits LayoutComponentBase
2+
3+
<div class="sidebar">
24
<NavMenu />
35
</div>
46

57
<div class="main">
68
<div class="top-row px-4">
7-
<a href="http://blazor.net" target="_blank" class="ml-md-auto">About</a>
9+
<a href="https://docs.microsoft.com/en-us/aspnet/" target="_blank">About</a>
810
</div>
911

1012
<div class="content px-4">
1113
<Switch>
1214
<Route Template="/">
13-
<HomePage CountValue="@countValue"></HomePage>
15+
<Index CountValue="@countValue"></Index>
1416
</Route>
1517
<Route Template="/counter">
16-
<Counter @bind-CurrentCount="countValue" ChangeCount="@changeCountValue"></Counter>
18+
<Counter @bind-CurrentCount="countValue" ChangeCount="@ChangeCountValue"></Counter>
1719
</Route>
1820
<Route Template="/counter/{init:int}">
19-
<Counter @bind-CurrentCount="countValue" ChangeCount="@changeCountValue"></Counter>
21+
<Counter @bind-CurrentCount="countValue" ChangeCount="@ChangeCountValue"></Counter>
2022
</Route>
2123
<Route Template="/fetchdata">
2224
<FetchData></FetchData>
@@ -32,9 +34,9 @@
3234
@code {
3335
private int countValue { get; set; } = 0;
3436

35-
void changeCountValue(int value)
37+
void ChangeCountValue(int value)
3638
{
3739
countValue = value;
3840
this.StateHasChanged();
3941
}
40-
}
42+
}

BlazorRouter.Sample/Shared/SurveyPrompt.razor

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

BlazorRouter.Sample/Startup.cs

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,60 @@
1-
using Microsoft.AspNetCore.Components.Builder;
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using Microsoft.AspNetCore.Builder;
6+
using Microsoft.AspNetCore.Components;
7+
using Microsoft.AspNetCore.Hosting;
8+
using Microsoft.AspNetCore.HttpsPolicy;
9+
using Microsoft.Extensions.Configuration;
210
using Microsoft.Extensions.DependencyInjection;
11+
using Microsoft.Extensions.Hosting;
12+
using BlazorRouter.Sample.Data;
313

414
namespace BlazorRouter.Sample
515
{
616
public class Startup
717
{
18+
public Startup(IConfiguration configuration)
19+
{
20+
Configuration = configuration;
21+
}
22+
23+
public IConfiguration Configuration { get; }
24+
25+
// This method gets called by the runtime. Use this method to add services to the container.
26+
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
827
public void ConfigureServices(IServiceCollection services)
928
{
29+
services.AddRazorPages();
30+
services.AddServerSideBlazor();
31+
services.AddSingleton<WeatherForecastService>();
1032
}
1133

12-
public void Configure(IComponentsApplicationBuilder app)
34+
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
35+
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
1336
{
14-
app.AddComponent<App>("app");
37+
if (env.IsDevelopment())
38+
{
39+
app.UseDeveloperExceptionPage();
40+
}
41+
else
42+
{
43+
app.UseExceptionHandler("/Error");
44+
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
45+
app.UseHsts();
46+
}
47+
48+
app.UseHttpsRedirection();
49+
app.UseStaticFiles();
50+
51+
app.UseRouting();
52+
53+
app.UseEndpoints(endpoints =>
54+
{
55+
endpoints.MapBlazorHub();
56+
endpoints.MapFallbackToPage("/_Host");
57+
});
1558
}
1659
}
1760
}

BlazorRouter.Sample/_Imports.razor

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
@using System.Net.Http
1+
@using System.Net.Http
2+
@using Microsoft.AspNetCore.Authorization
3+
@using Microsoft.AspNetCore.Components.Authorization
24
@using Microsoft.AspNetCore.Components.Forms
3-
45
@using Microsoft.AspNetCore.Components.Routing
6+
@using Microsoft.AspNetCore.Components.Web
57
@using Microsoft.JSInterop
68
@using BlazorRouter.Sample
79
@using BlazorRouter.Sample.Shared
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Debug",
5+
"System": "Information",
6+
"Microsoft": "Information"
7+
}
8+
}
9+
}

BlazorRouter.Sample/appsettings.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft": "Warning",
6+
"Microsoft.Hosting.Lifetime": "Information"
7+
}
8+
},
9+
"AllowedHosts": "*"
10+
}

0 commit comments

Comments
 (0)