Skip to content

Commit

Permalink
Upgrade to 3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
dodyg committed Mar 6, 2020
1 parent cc3cc9b commit dafaedd
Show file tree
Hide file tree
Showing 19 changed files with 111 additions and 121 deletions.
57 changes: 0 additions & 57 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -277,63 +277,6 @@ To run these samples, simply open your command line console, go to each folder
We have been building a `RouteTemplate` manually using `TemplateSegment` and `TemplatePart`. In this example we are using `TemplateParser` to build the `RouteTemplate` using string.
* **Middleware (12)**
We will explore all aspect of middleware building in this section.
* [Middleware 1](/projects/middleware-1)
This example shows how to pass information from one middleware to another using `HttpContext.Items`.
* [Middleware 2](/projects/middleware-2)
As a general rule, only one of your Middleware should write to Response in an execution path. This sample shows how to work around this by buffering the Response.
e.g.
If path `/` involves the execution of Middleware 1, Middleware 2 and Middleware 3, only one of these should write to Response.
* [Middleware 3](/projects/middleware-3)
This is the simplest middleware class you can create.
* [Middleware 4](/projects/middleware-4)
Use `app.Map` (`MapMiddleware`) to configure your middleware pipeline to respond only on specific url path.
* [Middleware 5](/projects/middleware-5)
Nested `app.Map` (show `Request.Path` and `Request.PathBase`).
* [Middleware 6](/projects/middleware-6)
Use `app.MapWhen`(`MapWhenMiddleware`) and Nested `app.Map` (show `Request.Path` and `Request.PathBase`).
* [Middleware 7](/projects/middleware-7)
Use `MapMiddleware` and `MapWhenMiddleware` directly without using extensions (show `Request.Path` and `Request.PathBase`).
* [Middleware 8](/projects/middleware-8)
Demonstrate the various ways you can inject dependency to your middleware class *manually*.
* [Middleware 9](/projects/middleware-9)
Demonstrate how to ASP.NET Core built in DI (Dependency Injection) mechanism to provide dependency for your middleware.
* [Middleware 10](/projects/middleware-10)
Demonstrate that a middleware is a singleton.
* [Middleware 11](/projects/middleware-11)
This sample is similar to `Middleware 10` except that this one implement `IMiddleware` to create Factory-based middleware activation. This means that you can create a middleware that is not a singleton (either Transient or Scoped).
* [Middleware 12](/projects/middleware-12)
Contrast the usage of `MapWhen` (which branch execution) and `UseWhen` (which doesn't branch execution) in configuring your Middleware.
* **Dependency Injection (2)**
Expand Down
18 changes: 0 additions & 18 deletions projects/2-0/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,24 +52,6 @@ Note that all the code here will run on ASP.NET Core 2.0 however these samples u
This exists on since .NET Core 1.0 however the configuration for the cookie has changed slightly. We are using ```IAntiForgery``` interface to store and generate anti forgery token to prevent XSRF/CSRF attacks.
* [Razor Pages Basic](razor-pages-basic)
This is the simplest example of the brand new `Razor Pages`. It shows the two approaches to `Razor Pages`, one with inline code behind and another with separate code behind.
* [Razor Pages and MVC Basic](razor-pages-mvc)
Compare and contrast on how the same task can be performed by using `Razor Pages` and `MVC`.
This sample also shows you how to us `Entity Framework Core` In-Memory Database.
* [UseRouter extension](use-router)
Use ```app.UseRouter()``` extension to create minimalistic HTTP services similar to Nancy.
* [UseRouter extension 2](use-router-2)
Use ```app.UseRouter()``` with alternative lambda signature.
* [IHostedService](ihosted-service)
Implement background tasks using the new `IHostedService` interface.
55 changes: 55 additions & 0 deletions projects/middleware/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Middleware (12)

We will explore all aspect of middleware building in this section.

* [Middleware 1](/projects/middleware/middleware-1)

This example shows how to pass information from one middleware to another using `HttpContext.Items`.

* [Middleware 2](/projects/middleware/middleware-2)

As a general rule, only one of your Middleware should write to Response in an execution path. This sample shows how to work around this by buffering the Response.

e.g.

If path `/` involves the execution of Middleware 1, Middleware 2 and Middleware 3, only one of these should write to Response.

* [Middleware 3](/projects/middleware/middleware-3)

This is the simplest middleware class you can create.

* [Middleware 4](/projects/middleware/middleware-4)

Use `app.Map` (`MapMiddleware`) to configure your middleware pipeline to respond only on specific url path.

* [Middleware 5](/projects/middleware/middleware-5)

Nested `app.Map` (show `Request.Path` and `Request.PathBase`).

* [Middleware 6](/projects/middleware/middleware-6)

Use `app.MapWhen`(`MapWhenMiddleware`) and Nested `app.Map` (show `Request.Path` and `Request.PathBase`).

* [Middleware 7](/projects/middleware/middleware-7)

Use `MapMiddleware` and `MapWhenMiddleware` directly without using extensions (show `Request.Path` and `Request.PathBase`).

* [Middleware 8](/projects/middleware/middleware-8)

Demonstrate the various ways you can inject dependency to your middleware class *manually*.

* [Middleware 9](/projects/middleware/middleware-9)

Demonstrate how to ASP.NET Core built in DI (Dependency Injection) mechanism to provide dependency for your middleware.

* [Middleware 10](/projects/middleware/middleware-10)

Demonstrate that a middleware is a singleton.

* [Middleware 11](/projects/middleware/middleware-11)

This sample is similar to `Middleware 10` except that this one implement `IMiddleware` to create Factory-based middleware activation. This means that you can create a middleware that is not a singleton (either Transient or Scoped).

* [Middleware 12](/projects/middleware/middleware-12)

Contrast the usage of `MapWhen` (which branch execution) and `UseWhen` (which doesn't branch execution) in configuring your Middleware.
12 changes: 11 additions & 1 deletion projects/razor-pages/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
# Razor Pages (4)
# Razor Pages

* [Hello World](/projects/razor-pages/hello-world)

This is the simplest example for Razor Page. Razor Page by default routes `.cshtml` files with `@page` attribute under `/Pages`. So `/Pages/Index.cshtml` becomes `/` and `/Pages/AboutUs.cshtml` becomes `/AboutUs`.

* [Razor Pages Basic](/projects/razor-pages/razor-pages-basic)

This sample shows the two approaches to `Razor Pages`, one with inline code behind and another with separate code behind.

* [Razor Pages and MVC Basic](razor-pages-mvc)

Compare and contrast on how the same task can be performed by using `Razor Pages` and `MVC`.
This sample also shows you how to us `Entity Framework Core` In-Memory Database.


* [Routing](/projects/razor-pages/routing)

Use `@page` directive on your Razor Page file to customize the url of your Razor Page. Each Razor Page can only contain 1 `@page` definition.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using RazorPagesMvc.Data;
using PracticalAspNetCore.Data;
using System.Threading.Tasks;

namespace RazorPagesMvc.Controllers
namespace PracticalAspNetCore.Controllers
{
[Route("Mvc")]
public class EntryController : Controller
Expand Down
2 changes: 1 addition & 1 deletion projects/razor-pages/razor-pages-mvc/Data/Entry.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.ComponentModel.DataAnnotations;

namespace RazorPagesMvc.Data
namespace PracticalAspNetCore.Data
{
public class Entry
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Microsoft.EntityFrameworkCore;

namespace RazorPagesMvc.Data
namespace PracticalAspNetCore.Data
{
public class GuestbookContext : DbContext
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@page
@model RazorPagesMvcCrud.Pages.CreateModel
@model PracticalAspNetCore.Pages.CreateModel
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

<html>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using RazorPagesMvc.Data;
using PracticalAspNetCore.Data;
using System.Threading.Tasks;

namespace RazorPagesMvcCrud.Pages
namespace PracticalAspNetCore.Pages
{
public class CreateModel : PageModel
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@page "{id:int}"
@model RazorPagesMvcCrud.Pages.EditModel
@model PracticalAspNetCore.Pages.EditModel
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

<h1>Edit Guestbook Entry @Model.Entry.Id</h1>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using RazorPagesMvc.Data;
using PracticalAspNetCore.Data;
using Microsoft.EntityFrameworkCore;

namespace RazorPagesMvcCrud.Pages
namespace PracticalAspNetCore.Pages
{
public class EditModel : PageModel
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@page
@model RazorPagesMvcCrud.Pages.IndexRazorPagesModel
@model PracticalAspNetCore.Pages.IndexRazorPagesModel
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

<h1>Razor Pages Implementation</h1>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using RazorPagesMvc.Data;
using PracticalAspNetCore.Data;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;

namespace RazorPagesMvcCrud.Pages
namespace PracticalAspNetCore.Pages
{
public class IndexRazorPagesModel : PageModel
{
Expand Down
27 changes: 25 additions & 2 deletions projects/razor-pages/razor-pages-mvc/Program.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,31 @@
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using PracticalAspNetCore.Data;
using Microsoft.Extensions.Hosting;

namespace RazorPagesMvc
namespace PracticalAspNetCore
{
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<GuestbookContext>(o =>
o.UseInMemoryDatabase("GuestbookDatabase"));
services.AddMvc();
}

public void Configure(IApplicationBuilder app)
{
app.UseRouting();
app.UseEndpoints(endpoints => {
endpoints.MapDefaultControllerRoute();
endpoints.MapRazorPages();
});
}
}

public class Program
{
public static void Main(string[] args)
Expand Down
23 changes: 0 additions & 23 deletions projects/razor-pages/razor-pages-mvc/Startup.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@model RazorPagesMvc.Data.Entry
@model PracticalAspNetCore.Data.Entry
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

<html>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@model RazorPagesMvc.Data.Entry
@model PracticalAspNetCore.Data.Entry
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

@{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@model List<RazorPagesMvc.Data.Entry>
@model List<PracticalAspNetCore.Data.Entry>
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
<h1>MVC Implementation</h1>
<p>Add your entry to guestbook.</p>
Expand Down
8 changes: 4 additions & 4 deletions projects/razor-pages/razor-pages-mvc/razor-pages-mvc.csproj
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>RazorPagesMvc</RootNamespace>
<AssemblyName>RazorPagesMvc</AssemblyName>
</PropertyGroup>


<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="3.1.2" />
</ItemGroup>
</Project>

0 comments on commit dafaedd

Please sign in to comment.