remove mkdocs specific syntax

This commit is contained in:
Marcello 2024-06-16 19:14:59 +02:00
parent 8d08c1964f
commit 8026e1465b
Signed by: m-lamonaca
SSH key fingerprint: SHA256:8db8uii6Gweq7TbKixFBioW2T8CbgtyFETyYL3cr3zk
77 changed files with 1128 additions and 1128 deletions

View file

@ -18,7 +18,7 @@ The component class is usually written in the form of a Razor markup page with a
[Blazor Components](https://docs.microsoft.com/en-us/aspnet/core/blazor/components/)
```cs linenums="1"
```cs
@page "/route/{RouteParameter}" // make component accessible from a URL
@page "/route/{RouteParameter?}" // specify route parameter as optional
@page "/route/{RouteParameter:<type>}" // specify route parameter type
@ -59,7 +59,7 @@ The component class is usually written in the form of a Razor markup page with a
It's now possible to pass state when navigating in Blazor apps using the `NavigationManager`.
```cs linenums="1"
```cs
navigationManager.NavigateTo("/<route>", new NavigationOptions { HistoryEntryState = value });
```
@ -67,12 +67,12 @@ This mechanism allows for simple communication between different pages. The spec
### Blazor WASM
```cs linenums="1"
```cs
// setup state singleton
builder.Services.AddSingleton<StateContainer>();
```
```cs linenums="1"
```cs
// StateContainer singleton
using System;
@ -96,7 +96,7 @@ public class StateContainer
}
```
```cs linenums="1"
```cs
// component that changes the state
@inject StateContainer State
@ -113,7 +113,7 @@ public class StateContainer
}
```
```cs linenums="1"
```cs
// component that should be update on state change
@implements IDisposable
@inject StateContainer State
@ -139,7 +139,7 @@ public class StateContainer
## Data Binding & Events
```cs linenums="1"
```cs
<p>
<button @on{DOM EVENT}="{DELEGATE}" />
<button @on{DOM EVENT}="{DELEGATE}" @on{DOM EVENT}:preventDefault /> // prevent default action
@ -198,7 +198,7 @@ public class StateContainer
To render a Blazor component from JavaScript, first register it as a root component for JavaScript rendering and assign it an identifier:
```cs linenums="1"
```cs
// Blazor Server
builder.Services.AddServerSideBlazor(options =>
{
@ -211,7 +211,7 @@ builder.RootComponents.RegisterForJavaScript<Counter>(identifier: "counter");
Load Blazor into the JavaScript app (`blazor.server.js` or `blazor.webassembly.js`) and then render the component from JavaScript into a container element using the registered identifier, passing component parameters as needed:
```js linenums="1"
```js
let containerElement = document.getElementById('my-counter');
await Blazor.rootComponents.add(containerElement, 'counter', { incrementAmount: 10 });
```
@ -223,6 +223,6 @@ Custom elements use standard HTML interfaces to implement custom HTML elements.
To create a custom element using Blazor, register a Blazor root component as custom elements like this:
```cs linenums="1"
```cs
options.RootComponents.RegisterAsCustomElement<Counter>("my-counter");
```

View file

@ -33,7 +33,7 @@ Short-circuiting is often desirable because it avoids unnecessary work.
It's possible to perform actions both *before* and *after* the next delegate:
```cs linenums="1"
```cs
// "inline" middleware, best if in own class
app.Use(async (context, next) =>
{
@ -45,7 +45,7 @@ app.Use(async (context, next) =>
`Run` delegates don't receive a next parameter. The first `Run` delegate is always terminal and terminates the pipeline.
```cs linenums="1"
```cs
// "inline" middleware, best if in own class
app.Use(async (context, next) =>
{
@ -69,7 +69,7 @@ The Endpoint middleware executes the filter pipeline for the corresponding app t
The order that middleware components are added in the `Startup.Configure` method defines the order in which the middleware components are invoked on requests and the reverse order for the response. The order is **critical** for security, performance, and functionality.
```cs linenums="1"
```cs
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
@ -121,7 +121,7 @@ Unlike with `MapWhen`, this branch is rejoined to the main pipeline if it doesn'
Middleware is generally encapsulated in a class and exposed with an extension method.
```cs linenums="1"
```cs
public class CustomMiddleware
{
private readonly RequestDelegate _next;
@ -152,7 +152,7 @@ The middleware class **must** include:
## Middleware Extension Methods
```cs linenums="1"
```cs
using Microsoft.AspNetCore.Builder;
public static class MiddlewareExtensions
@ -164,7 +164,7 @@ public static class MiddlewareExtensions
}
```
```cs linenums="1"
```cs
// other middlewares
app.UseCustom(); // add custom middleware in the pipeline

View file

@ -2,7 +2,7 @@
> **Note**: Requires .NET 6+
```cs linenums="1"
```cs
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddSingleton<IService, Service>();
@ -41,7 +41,7 @@ Setting a value is done with `dotnet user-secrets set <key> <value>`, keys can b
## Swagger
```cs linenums="1"
```cs
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
@ -59,7 +59,7 @@ app.MapPost("/route", Handler).Accepts<Type>(contentType);
## MVC
```cs linenums="1"
```cs
builder.Services.AddControllersWithViews();
//or
builder.Services.AddControllers();
@ -95,7 +95,7 @@ app.MapControllerRoute(
To define routes and handlers using Minimal APIs, use the `Map(Get|Post|Put|Delete)` methods.
```cs linenums="1"
```cs
// the dependencies are passed as parameters in the handler delegate
app.MapGet("/route/{id}", (IService service, int id) => {
@ -112,7 +112,7 @@ IResult Search(int id, int? page = 1, int? pageSize = 10) { /* ... */ }
The `MapGroup()` extension method, which helps organize groups of endpoints with a common prefix.
It allows for customizing entire groups of endpoints with a singe call to methods like `RequireAuthorization()` and `WithMetadata()`.
```cs linenums="1"
```cs
var group = app.MapGroup("<route-prefix>");
group.MapGet("/", GetAllTodos); // route: /<route-prefix>
@ -126,14 +126,14 @@ group.MapGet("/{id}", GetTodo); // route: /<route-prefix>/{id}
The `Microsoft.AspNetCore.Http.TypedResults` static class is the “typed” equivalent of the existing `Microsoft.AspNetCore.Http.Results` class.
It's possible to use `TypedResults` in minimal APIs to create instances of the in-framework `IResult`-implementing types and preserve the concrete type information.
```cs linenums="1"
```cs
public static async Task<IResult> GetAllTodos(TodoDb db)
{
return TypedResults.Ok(await db.Todos.ToArrayAsync());
}
```
```cs linenums="1"
```cs
[Fact]
public async Task GetAllTodos_ReturnsOkOfObjectResult()
{
@ -152,7 +152,7 @@ public async Task GetAllTodos_ReturnsOkOfObjectResult()
The `Results<TResult1, TResult2, TResultN>` generic union types, along with the `TypesResults` class, can be used to declare that a route handler returns multiple `IResult`-implementing concrete types.
```cs linenums="1"
```cs
// Declare that the lambda returns multiple IResult types
app.MapGet("/todos/{id}", async Results<Ok<Todo>, NotFound> (int id, TodoDb db)
{
@ -164,7 +164,7 @@ app.MapGet("/todos/{id}", async Results<Ok<Todo>, NotFound> (int id, TodoDb db)
## Filters
```cs linenums="1"
```cs
public class ExampleFilter : IRouteHandlerFilter
{
public async ValueTask<object?> InvokeAsync(RouteHandlerInvocationContext context, RouteHandlerFilterDelegate next)
@ -177,7 +177,7 @@ public class ExampleFilter : IRouteHandlerFilter
}
```
```cs linenums="1"
```cs
app.MapPost("/route", Handler).AddFilter<ExampleFilter>();
```
@ -191,7 +191,7 @@ With Minimal APIs it's possible to access the contextual information by passing
- `ClaimsPrincipal`
- `CancellationToken` (RequestAborted)
```cs linenums="1"
```cs
app.MapGet("/hello", (ClaimsPrincipal user) => {
return "Hello " + user.FindFirstValue("sub");
});
@ -201,7 +201,7 @@ app.MapGet("/hello", (ClaimsPrincipal user) => {
The `Microsoft.AspNetCore.OpenApi` package exposes a `WithOpenApi` extension method that generates an `OpenApiOperation` derived from a given endpoints route handler and metadata.
```cs linenums="1"
```cs
app.MapGet("/todos/{id}", (int id) => ...)
.WithOpenApi();
@ -217,7 +217,7 @@ app.MapGet("/todos/{id}", (int id) => ...)
Using [Minimal Validation](https://github.com/DamianEdwards/MinimalValidation) by Damian Edwards.
Alternatively it's possible to use [Fluent Validation](https://fluentvalidation.net/).
```cs linenums="1"
```cs
app.MapPost("/widgets", (Widget widget) => {
var isValid = MinimalValidation.TryValidate(widget, out var errors);
@ -240,7 +240,7 @@ class Widget
## JSON Serialization
```cs linenums="1"
```cs
// Microsoft.AspNetCore.Http.Json.JsonOptions
builder.Services.Configure<JsonOptions>(opt =>
{
@ -250,7 +250,7 @@ builder.Services.Configure<JsonOptions>(opt =>
## Authorization
```cs linenums="1"
```cs
builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer();
builder.Services.AddAuthorization();
@ -283,13 +283,13 @@ app.MapGet("/special-secret", () => "This is a special secret!")
The `user-jwts` tool is similar in concept to the existing `user-secrets` tools, in that it can be used to manage values for the app that are only valid for the current user (the developer) on the current machine.
In fact, the `user-jwts` tool utilizes the `user-secrets` infrastructure to manage the key that the JWTs will be signed with, ensuring its stored safely in the user profile.
```sh linenums="1"
```sh
dotnet user-jwts create # configure a dev JWT fot the current user
```
## Output Caching
```cs linenums="1"
```cs
builder.Services.AddOutputCaching(); // no special options
builder.Services.AddOutputCaching(options =>
{
@ -321,7 +321,7 @@ app.MapGet("/<route>", [OutputCache(/* options */)]RouteHandler);
### Cache Eviction
```cs linenums="1"
```cs
app.MapGet("/<route-one>", RouteHandler).CacheOutput(x => x.Tag("<tag>")); // tag cache portion
@ -333,11 +333,11 @@ app.MapGet("/<route-two>", (IOutputCacheStore cache, CancellationToken token) =>
### Custom Cache Policy
```cs linenums="1"
```cs
app.MapGet("/<route-one>", RouteHandler).CacheOutput(x => x.AddCachePolicy<CustomCachePolicy>());
```
```cs linenums="1"
```cs
class CustomCachePolicy : IOutputCachePolicy
{
public ValueTask CacheRequestAsync(OutputCacheContext context, CancellationToken cancellationToken) { }
@ -352,7 +352,7 @@ class CustomCachePolicy : IOutputCachePolicy
The *options pattern* uses classes to provide strongly-typed access to groups of related settings.
```json linenums="1"
```json
{
"SecretKey": "Secret key value",
"TransientFaultHandlingOptions": {
@ -369,7 +369,7 @@ The *options pattern* uses classes to provide strongly-typed access to groups of
}
```
```cs linenums="1"
```cs
// options model for binding
public class TransientFaultHandlingOptions
{
@ -378,13 +378,13 @@ public class TransientFaultHandlingOptions
}
```
```cs linenums="1"
```cs
// setup the options
builder.Services.Configure<TransientFaultHandlingOptions>(builder.Configuration.GetSection<TransientFaultHandlingOptions>(nameof(Options)));
builder.Services.Configure<TransientFaultHandlingOptions>(builder.Configuration.GetSection<TransientFaultHandlingOptions>(key));
```
```cs linenums="1"
```cs
class DependsOnOptions
{
private readonly IOptions<TransientFaultHandlingOptions> _options;

View file

@ -2,7 +2,7 @@
## Markup
```cs linenums="1"
```cs
@page // set this as razor page
@model <App>.Models.Entity // if MVC set type of elements passed to the view
@ -35,7 +35,7 @@
Example:
```html linenums="1"
```html
<!-- tag helpers for a lin in ASP.NET MVC -->
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Index">Home</a>
```
@ -44,7 +44,7 @@ Example:
The `@addTagHelper` directive makes Tag Helpers available to the view. Generally, the view file is `Pages/_ViewImports.cshtml`, which by default is inherited by all files in the `Pages` folder and subfolders, making Tag Helpers available.
```cs linenums="1"
```cs
@using <App>
@namespace <App>.Pages // or <Project>.Models
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@ -57,7 +57,7 @@ The first parameter after `@addTagHelper` specifies the Tag Helpers to load (`*`
It's possible to disable a Tag Helper at the element level with the Tag Helper opt-out character (`!`)
```cshtml linenums="1"
```cshtml
<!-- disable email validation -->
<!span asp-validation-for="Email" ></!span>
```
@ -66,7 +66,7 @@ It's possible to disable a Tag Helper at the element level with the Tag Helper o
The `@tagHelperPrefix` directive allows to specify a tag prefix string to enable Tag Helper support and to make Tag Helper usage explicit.
```cshtml linenums="1"
```cshtml
@tagHelpersPrefix th:
```
@ -74,7 +74,7 @@ The `@tagHelperPrefix` directive allows to specify a tag prefix string to enable
[Understanding Html Helpers](https://stephenwalther.com/archive/2009/03/03/chapter-6-understanding-html-helpers)
```cs linenums="1"
```cs
@model <App>.Models.Entity
// Display the name of the property
@ -112,7 +112,7 @@ The `@tagHelperPrefix` directive allows to specify a tag prefix string to enable
In `ViewModel.cs`:
```cs linenums="1"
```cs
class ViewModel
{
public int EntityId { get; set; } // value selected in form ends up here
@ -126,7 +126,7 @@ class ViewModel
In `View.cs`
```cs linenums="1"
```cs
@model ViewModel
<form asp-controller="Controller" asp-action="PostAction">
@ -140,7 +140,7 @@ In `View.cs`
In `Controller.cs`:
```cs linenums="1"
```cs
public IActionResult GetAction()
{
var vm = new ViewModel();

View file

@ -8,7 +8,7 @@ The SignalR Hubs API enables to call methods on connected clients from the serve
In `Startup.cs`:
```cs linenums="1"
```cs
builder.Services.AddSignalR();
var app = builder.Build();
@ -21,7 +21,7 @@ app.UseEndpoints(endpoints =>
### Creating Hubs
```cs linenums="1"
```cs
public class CustomHub : Hub
{
public task HubMethod(Type args)
@ -46,7 +46,7 @@ A drawback of using `SendAsync` is that it relies on a magic string to specify t
An alternative to using SendAsync is to strongly type the Hub with `Hub<T>`.
```cs linenums="1"
```cs
public interface IHubClient
{
// matches method to be called on the client
@ -54,7 +54,7 @@ public interface IHubClient
}
```
```cs linenums="1"
```cs
public class CustomHub : Hub<IHubClient>
{
public Task HubMethod(Type args)
@ -72,7 +72,7 @@ Using a strongly typed `Hub<T>` disables the ability to use `SendAsync`. Any met
The SignalR Hubs API provides the OnConnectedAsync and OnDisconnectedAsync virtual methods to manage and track connections. Override the OnConnectedAsync virtual method to perform actions when a client connects to the Hub, such as adding it to a group.
```cs linenums="1"
```cs
public override async Task OnConnectedAsync()
{
await Groups.AddToGroupAsync(Context.ConnectionId, "GroupName");
@ -98,7 +98,7 @@ If the Hub throws an exception, connections aren't closed. By default, SignalR r
If you have an exceptional condition you *do* want to propagate to the client, use the `HubException` class. If you throw a `HubException` from your hub method, SignalR will send the entire message to the client, unmodified.
```cs linenums="1"
```cs
public Task ThrowException()
{
throw new HubException("This error will be sent to the client!");
@ -109,7 +109,7 @@ public Task ThrowException()
### Installing the client package
```sh linenums="1"
```sh
npm init -y
npm install @microsoft/signalr
```
@ -118,7 +118,7 @@ npm installs the package contents in the `node_modules\@microsoft\signalr\dist\b
Reference the SignalR JavaScript client in the `<script>` element. For example:
```html linenums="1"
```html
<script src="~/lib/signalr/signalr.js"></script>
```
@ -126,7 +126,7 @@ Reference the SignalR JavaScript client in the `<script>` element. For example:
[Reconnect Clients Docs](https://docs.microsoft.com/en-us/aspnet/core/signalr/javascript-client#reconnect-clients)
```js linenums="1"
```js
const connection = new signalR.HubConnectionBuilder()
.withUrl("/hub/endpoint")
.configureLogging(signalR.LogLevel.Information)
@ -158,7 +158,7 @@ JavaScript clients call public methods on hubs via the `invoke` method of the `H
- The name of the hub method.
- Any arguments defined in the hub method.
```js linenums="1"
```js
try {
await connection.invoke("HubMethod", args);
} catch (err) {
@ -177,6 +177,6 @@ To receive messages from the hub, define a method using the `on` method of the `
- The name of the JavaScript client method.
- Arguments the hub passes to the method.
```cs linenums="1"
```cs
connection.on("ClientMethod", (args) => { /* ... */});
```

View file

@ -4,7 +4,7 @@
The fist loaded page is `Default.aspx` and its underlying code.
```html linenums="1"
```html
<!-- directive -->
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Project.Default" %>
@ -26,7 +26,7 @@ The fist loaded page is `Default.aspx` and its underlying code.
### Page Directive
```cs linenums="1"
```cs
<%@ Page Language="C#" // define language used (can be C# or VB)
AutoEventWireup="true" // automatically create and setup event handlers
CodeBehind="Default.aspx.cs" // define the underlying code file
@ -35,7 +35,7 @@ The fist loaded page is `Default.aspx` and its underlying code.
### Web Controls
```xml linenums="1"
```xml
<asp:Control ID="" runat="server" ...></asp:Control>
<!-- Label: empty text will diplay ID, use empty space as text for empty label -->
@ -59,7 +59,7 @@ The fist loaded page is `Default.aspx` and its underlying code.
## `Page.aspx.cs`
```cs linenums="1"
```cs
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)