December 28, 2023

Ahead of Time Compilation (AOT) in .NET 8

Ahead of Time Compilation (AOT) is a technology that has been gaining momentum in the world of software development, and .NET 8 brings exciting advancements in this area. AOT offers significant advantages in terms of performance and security, making it an essential feature for modern .NET applications. Let's explore AOT in .NET 8 and its benefits.

What is Ahead of Time Compilation (AOT)?

AOT is a compilation technique that converts high-level code, such as C# or F#, into native machine code before the application is run. Unlike Just-In-Time (JIT) compilation, which compiles code at runtime, AOT compiles code ahead of time, resulting in several advantages: 

Performance Boost: AOT-compiled code runs faster since it doesn't require runtime compilation. This leads to reduced startup times and improved overall application performance.

Predictable Behavior: AOT eliminates the JIT warm-up time, ensuring consistent and predictable application behavior across different executions.

Improved Security: AOT reduces the attack surface by removing the need for a JIT compiler at runtime, making it harder for attackers to exploit vulnerabilities.

.NET 8 introduces enhanced AOT support, making it easier than ever to leverage this technology in your applications. Here are some key improvements:

Single-File AOT: .NET 8 allows you to create single-file AOT-compiled applications, simplifying deployment and distribution.

Cross-Platform AOT: AOT is no longer limited to Windows. .NET 8 brings cross-platform AOT support, enabling AOT-compiled apps to run on various operating systems.

Improved Interoperability: .NET 8 enhances the interoperability between AOT-compiled code and JIT-compiled code, ensuring smooth integration of AOT into existing projects.

In .NET 8, AOT makes your software faster, safer, and works on different devices. I Love it since it makes the Minimal Apis even faster. 

December 17, 2023

How to add Api key validation in Swagger

Just a quick post on how to add api key validation in swagger docs. Pretty easy and here is the code to add in AddSwaggerGen in the program.cs file. You can define your own Api key validation middleware.


    builder.Services.AddSwaggerGen(c =>
    {
    c.AddSecurityDefinition("api_key", new OpenApiSecurityScheme
    {
    Type = SecuritySchemeType.ApiKey,
    Name = "Authorization",
    In = ParameterLocation.Header,
    Description = "API key needed to access the endpoints."
    });

    // Define your security requirement (optional)
    c.AddSecurityRequirement(new OpenApiSecurityRequirement
    {
     {
    new OpenApiSecurityScheme
     {
     Reference = new OpenApiReference
    {
     Type = ReferenceType.SecurityScheme,
     Id = "api_key"
     }
    },
     new string[] { }
    }
    });
    });

December 6, 2023

Title: Announcing My New Book: Crafting Minimal APIs with a Functional Twist!

 

I am thrilled to share with all of you a journey I've passionately embarked on – writing a book dedicated to the world of Minimal APIs with a functional approach. This book is not just a guide; it's a deep dive into the efficient and innovative world of Minimal APIs, explored through the lens of functional programming. I've poured my experience and insights into this work, aiming to offer a fresh perspective on building lean, effective APIs. Whether you're a seasoned developer or just starting out, this book promises to enrich your understanding and skills in creating powerful, minimalistic APIs with a functional twist. Stay tuned for more updates and snippets from my book!


Coming Soon!