- Propagate headers with .NET Core Web API
- StreamConfiguationSource - reading configuration from any Stream source
- ServiceProviderOptions.ValidateOnBuild - validates the dependencis injected into DI
- Module Initializers - Module initializers are very useful when you want to eager load something before anything else executes
[ModuleInitializer]
public static void Magic()
{
// Some powerful stuff here...
}
- Simplified null checking
- null coalesce operator and parentheses to automagically instantiate collections
private IList<Foo> _foo;
public IList<Foo> ListOfFoo
{ get { return _foo ?? (_foo = new List<Foo>()); } }
- The 'default' keyword in generic types: T t = default(T);
- LINQ -
"map" => Select
Transforms data from one form into another
"reduce" => Aggregate
Aggregates values into a single result
"filter" => Where
Filters data based on a criteria
// assign value of the switch to a variable
var text = light.Status switch
{
ON => "Light is on",
OFF => "Light is off",
_ => "Unknown status"
}
- null-coalescing operators - var variable = MightReturnNull() ?? "default";
- file-scoped namespaces - namespace MyNameSpace; - begining of file
- Startup Hooks - Register Code to execute before Program.main
- IConfigurationRoot.DebugView()
Propagate headers with .NET Core Web API
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.HeaderPropagation" Version="6.0.10" />
</ItemGroup>
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers();
builder.Services.AddHeaderPropagation(o =>
{
// propogating the HttpRequest Headers
o.Headers.Add("Authorization");
});
builder.Services.AddHttpClient("DemoApp").AddHeaderPropagation();
var app = builder.Build();
// Configure the HTTP request pipeline.
app.UseAuthorization();
app.UseHeaderPropagation();
app.MapControllers();
app.Run();