This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Collections.Immutable; | |
using System.IO; | |
using System.Linq; | |
using System.Reflection; | |
using System.Runtime.Loader; | |
using System.Threading; | |
using Microsoft.AspNetCore.Builder; | |
using Microsoft.AspNetCore.Hosting; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.Extensions.Configuration.Memory; | |
var builder = WebApplication.CreateBuilder(args); | |
builder.Configuration.AddConfigurationDefaults(new() | |
{ | |
{ "request:timeout", "60" } | |
}); | |
var app = builder.Build(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void ConfigureServices(IServiceCollection services) | |
{ | |
services.AddHttpClient("myclient"); | |
// Global header propagation for any HttpClient that comes from HttpClientFactory | |
services.AddHeaderPropagation(options => | |
{ | |
options.HeaderNames.Add("Correlation-Id"); | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Text.Json; | |
using System.Text.Json.Serialization; | |
var data = new[] | |
{ | |
"Hello"u8.ToArray(), | |
"Twitter"u8.ToArray(), | |
"Optimize"u8.ToArray() | |
} | |
.Select(m => new Message(m)).ToArray(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Data.Common; | |
using System.Runtime.CompilerServices; | |
using System.Text; | |
using Npgsql; | |
GetCatalogItemsSql(null, null, null, 10); | |
void GetCatalogItemsSql(int? catalogBrandId, int? before, int? after, int pageSize) | |
{ | |
// This looks like it would be susceptible to SQL injection, but it's not. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.AspNetCore.Http.Features; | |
using Microsoft.AspNetCore.WebUtilities; | |
using ProtoBuf; | |
var builder = WebApplication.CreateBuilder(args); | |
var app = builder.Build(); | |
app.MapGet("/", () => "POST a protobuf message to the /"); | |
app.MapPost("/", (Proto<Person> p) => Results.Extensions.Protobuf(p.Item)) | |
.Accepts<Person>("application/protobuf"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class ConfigurationBinderExtensions | |
{ | |
public static ValidateOptionsResult BindAndValidate<TOptions>(this IConfiguration configuration, TOptions instance) where TOptions : class, new() | |
{ | |
configuration.Bind(instance); | |
var validateOptions = new DataAnnotationValidateOptions<TOptions>(Options.DefaultName); | |
return validateOptions.Validate(Options.DefaultName, instance); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Buffers; | |
using System.Net.WebSockets; | |
var builder = WebApplication.CreateBuilder(args); | |
var app = builder.Build(); | |
app.MapGet("/ws", async (HttpContext context) => | |
{ | |
const int MaxMessageSize = 1024 * 1024; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.ComponentModel.DataAnnotations; | |
using Microsoft.EntityFrameworkCore; | |
var builder = WebApplication.CreateBuilder(args); | |
var app = builder.Build(); | |
app.MapPost("/todos", async (CreateTodo createTodo, TodoDb db) => | |
{ | |
// This is where the implicit conversion comes in | |
db.Todos.Add(createTodo); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.IO.Pipelines; | |
using System.Net; | |
using System.Net.Security; | |
using Microsoft.AspNetCore.Connections; | |
using Microsoft.AspNetCore.Connections.Features; | |
using Microsoft.AspNetCore.Http.Features; | |
using Microsoft.AspNetCore.Server.Kestrel.Core; | |
var builder = WebApplication.CreateBuilder(args); |