Skip to content

Commit

Permalink
Upgrade to ASP.NET Core 3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
hez2010 committed Nov 16, 2019
1 parent 26613a8 commit a1a9b48
Show file tree
Hide file tree
Showing 34 changed files with 315 additions and 255 deletions.
2 changes: 1 addition & 1 deletion BlazorRouter.Sample/App.razor
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<MainLayout></MainLayout>
<MainLayout />
13 changes: 2 additions & 11 deletions BlazorRouter.Sample/BlazorRouter.Sample.csproj
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>7.3</LangVersion>
<RazorLangVersion>3.0</RazorLangVersion>
<TargetFramework>netcoreapp3.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Blazor" Version="3.0.0-preview8.19405.7" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.HttpClient" Version="3.0.0-preview8.19405.7" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.Build" Version="3.0.0-preview8.19405.7" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Blazor.DevServer" Version="3.0.0-preview8.19405.7" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\BlazorRouter\BlazorRouter.csproj" />
</ItemGroup>
Expand Down
15 changes: 15 additions & 0 deletions BlazorRouter.Sample/Data/WeatherForecast.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System;

namespace BlazorRouter.Sample.Data
{
public class WeatherForecast
{
public DateTime Date { get; set; }

public int TemperatureC { get; set; }

public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);

public string Summary { get; set; }
}
}
25 changes: 25 additions & 0 deletions BlazorRouter.Sample/Data/WeatherForecastService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.Linq;
using System.Threading.Tasks;

namespace BlazorRouter.Sample.Data
{
public class WeatherForecastService
{
private static readonly string[] Summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};

public Task<WeatherForecast[]> GetForecastAsync(DateTime startDate)
{
var rng = new Random();
return Task.FromResult(Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = startDate.AddDays(index),
TemperatureC = rng.Next(-20, 55),
Summary = Summaries[rng.Next(Summaries.Length)]
}).ToArray());
}
}
}
2 changes: 1 addition & 1 deletion BlazorRouter.Sample/Pages/Counter.razor
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@
}
return Task.CompletedTask;
}
}
}
16 changes: 16 additions & 0 deletions BlazorRouter.Sample/Pages/Error.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
@page "/error"


<h1 class="text-danger">Error.</h1>
<h2 class="text-danger">An error occurred while processing your request.</h2>

<h3>Development Mode</h3>
<p>
Swapping to <strong>Development</strong> environment will display more detailed information about the error that occurred.
</p>
<p>
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
It can result in displaying sensitive information from exceptions to end users.
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
and restarting the app.
</p>
23 changes: 6 additions & 17 deletions BlazorRouter.Sample/Pages/FetchData.razor
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
@inject HttpClient Http
@using BlazorRouter.Sample.Data
@inject WeatherForecastService ForecastService

<h1>Weather forecast</h1>

<p>This component demonstrates fetching data from the server.</p>
<p>This component demonstrates fetching data from a service.</p>

@if (forecasts == null)
{
Expand All @@ -20,10 +21,9 @@ else
</tr>
</thead>
<tbody>
@for (var i = 0; i < forecasts.Length; i++)
@foreach (var forecast in forecasts)
{
var forecast = forecasts[i];
<tr @key="i">
<tr>
<td>@forecast.Date.ToShortDateString()</td>
<td>@forecast.TemperatureC</td>
<td>@forecast.TemperatureF</td>
Expand All @@ -39,17 +39,6 @@ else

protected override async Task OnInitializedAsync()
{
forecasts = await Http.GetJsonAsync<WeatherForecast[]>("sample-data/weather.json");
}

class WeatherForecast
{
public DateTime Date { get; set; }

public int TemperatureC { get; set; }

public int TemperatureF { get; set; }

public string Summary { get; set; }
forecasts = await ForecastService.GetForecastAsync(DateTime.Now);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

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

<SurveyPrompt Title="How is Blazor working for you?" />

<br />
<NavLink href="counter/500">
Click here to count from 500 directly.
Expand All @@ -15,4 +13,4 @@ Welcome to your new app. You have counted to @CountValue.

@code {
[Parameter] public int CountValue { get; set; }
}
}
22 changes: 22 additions & 0 deletions BlazorRouter.Sample/Pages/_Host.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
@page "/"
@namespace BlazorRouter.Sample.Pages
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>BlazorRouter.Sample</title>
<base href="~/" />
<link rel="stylesheet" href="css/bootstrap/bootstrap.min.css" />
<link href="css/site.css" rel="stylesheet" />
</head>
<body>
<app>
@(await Html.RenderComponentAsync<App>(RenderMode.ServerPrerendered))
</app>

<script src="_framework/blazor.server.js"></script>
</body>
</html>
2 changes: 0 additions & 2 deletions BlazorRouter.Sample/Pages/_Imports.razor

This file was deleted.

20 changes: 16 additions & 4 deletions BlazorRouter.Sample/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
using Microsoft.AspNetCore.Blazor.Hosting;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;

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

public static IWebAssemblyHostBuilder CreateHostBuilder(string[] args) =>
BlazorWebAssemblyHost.CreateDefaultBuilder()
.UseBlazorStartup<Startup>();
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
}
10 changes: 5 additions & 5 deletions BlazorRouter.Sample/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:52666/",
"sslPort": 0
"applicationUrl": "http://localhost:33502",
"sslPort": 44361
}
},
"profiles": {
Expand All @@ -18,10 +18,10 @@
"BlazorRouter.Sample": {
"commandName": "Project",
"launchBrowser": true,
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "http://localhost:52667/"
}
}
}
}
}
16 changes: 9 additions & 7 deletions BlazorRouter.Sample/Shared/MainLayout.razor
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
<div class="sidebar">
@inherits LayoutComponentBase

<div class="sidebar">
<NavMenu />
</div>

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

<div class="content px-4">
<Switch>
<Route Template="/">
<HomePage CountValue="@countValue"></HomePage>
<Index CountValue="@countValue"></Index>
</Route>
<Route Template="/counter">
<Counter @bind-CurrentCount="countValue" ChangeCount="@changeCountValue"></Counter>
<Counter @bind-CurrentCount="countValue" ChangeCount="@ChangeCountValue"></Counter>
</Route>
<Route Template="/counter/{init:int}">
<Counter @bind-CurrentCount="countValue" ChangeCount="@changeCountValue"></Counter>
<Counter @bind-CurrentCount="countValue" ChangeCount="@ChangeCountValue"></Counter>
</Route>
<Route Template="/fetchdata">
<FetchData></FetchData>
Expand All @@ -32,9 +34,9 @@
@code {
private int countValue { get; set; } = 0;

void changeCountValue(int value)
void ChangeCountValue(int value)
{
countValue = value;
this.StateHasChanged();
}
}
}
15 changes: 0 additions & 15 deletions BlazorRouter.Sample/Shared/SurveyPrompt.razor

This file was deleted.

49 changes: 46 additions & 3 deletions BlazorRouter.Sample/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,60 @@
using Microsoft.AspNetCore.Components.Builder;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using BlazorRouter.Sample.Data;

namespace BlazorRouter.Sample
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}

public IConfiguration Configuration { get; }

// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services.AddRazorPages();
services.AddServerSideBlazor();
services.AddSingleton<WeatherForecastService>();
}

public void Configure(IComponentsApplicationBuilder app)
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.AddComponent<App>("app");
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}

app.UseHttpsRedirection();
app.UseStaticFiles();

app.UseRouting();

app.UseEndpoints(endpoints =>
{
endpoints.MapBlazorHub();
endpoints.MapFallbackToPage("/_Host");
});
}
}
}
6 changes: 4 additions & 2 deletions BlazorRouter.Sample/_Imports.razor
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
@using System.Net.Http
@using System.Net.Http
@using Microsoft.AspNetCore.Authorization
@using Microsoft.AspNetCore.Components.Authorization
@using Microsoft.AspNetCore.Components.Forms

@using Microsoft.AspNetCore.Components.Routing
@using Microsoft.AspNetCore.Components.Web
@using Microsoft.JSInterop
@using BlazorRouter.Sample
@using BlazorRouter.Sample.Shared
Expand Down
9 changes: 9 additions & 0 deletions BlazorRouter.Sample/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
}
}
10 changes: 10 additions & 0 deletions BlazorRouter.Sample/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*"
}
Loading

0 comments on commit a1a9b48

Please sign in to comment.