In today's fast-paced digital landscape, developers need robust frameworks that deliver exceptional performance, security, and maintainability. The combination of Angular v20 for the front-end and .NET 9 with ASP.NET Core Web API for the back-end provides a powerful stack for building modern web applications. In this article, we'll explore how to leverage the latest features of both technologies to create high-performance applications with excellent developer experience.
Architecture and Design Philosophy
Separation of Concerns
Maintain clear separation between UI, API, and business logic:
- Angular handles UX, rendering, and client-side caching
- ASP.NET Core manages data, authentication, server-side caching, telemetry, and business rules
Contract-First Development
.NET 9 includes built-in OpenAPI support, enabling you to:
- Expose clear API contracts
- Generate typed clients in Angular
- Run contract tests during CI/CD
- Ensure API consistency across front-end and back-end
Deployment Options
- Decoupled: Serve Angular from CDN (ideal for scaling) with API behind load balancers
- Monolithic: Use .NET 9's MapStaticAssets() to serve Angular builds with optimized static file delivery (build-time compression, content-based ETags, and fingerprinting)
Angular v20: Modern Front-End Development
Angular v20 introduces several groundbreaking features that significantly improve performance and developer experience.
Key Features and Patterns
Signals for Fine-Grained Reactivity
typescript
// Using Signals for state management
import { signal, computed } from '@angular/core';
export class CartService {
items = signal<Item[]>([]);
total = computed(() =>
this.items().reduce((sum, item) => sum + item.price, 0)
);
}
Signals provide a single source of truth, reduce unnecessary change detection cycles, and offer clearer dependency graphs compared to traditional RxJS approaches.
HTTP Resource for Reactive Data Fetching
typescript
// Product component using httpResource
import { Component, signal } from '@angular/core';
import { httpResource } from '@angular/common/http';
@Component({
standalone: true,
template: `
<div *ngIf="products.hasValue()">
<div *ngFor="let p of products.value()">
{{ p.name }} — {{ p.price | currency }}
</div>
</div>
<div *ngIf="products.isLoading()">Loading…</div>
`
})
export class ProductListComponent {
page = signal(1);
products = httpResource(() => `/api/products?page=${this.page()}`);
}
The httpResource pattern provides reactive data fetching with built-in loading states, error handling, and request cancellation.
Zoneless Change Detection
typescript
// Enable zoneless mode in bootstrap
import { bootstrapApplication } from '@angular/platform-browser';
import { provideZonelessChangeDetection } from '@angular/core';
bootstrapApplication(AppComponent, {
providers: [provideZonelessChangeDetection()]
});
Zoneless mode eliminates zone.js overhead, reducing bundle size and improving runtime performance.
Server-Side Rendering with Incremental Hydration
typescript
// Enable incremental hydration
import { provideClientHydration, withIncrementalHydration } from '@angular/platform-browser';
bootstrapApplication(AppComponent, {
providers: [
provideClientHydration(withIncrementalHydration())
]
});
Incremental hydration improves perceived performance by hydrating only the visible parts of the page first.
.NET 9: High-Performance Back-End Development
.NET 9 brings significant improvements for building fast, secure, and scalable APIs.
Key Features and Patterns
Native AOT Compilation
xml
<!-- Enable Native AOT in .csproj -->
<PropertyGroup>
<PublishAot>true</PublishAot>
</PropertyGroup>
Native AOT produces self-contained, native binaries that offer:
- Reduced startup time
- Lower memory footprint
- Smaller deployment size
- Ideal for microservices and serverless environments
Built-in OpenAPI Support
csharp
// Program.cs
using Microsoft.AspNetCore.OpenApi;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddOpenApi();
var app = builder.Build();
if (app.Environment.IsDevelopment())
app.MapOpenApi(); // Exposes openapi.json
.NET 9's built-in OpenAPI support simplifies API documentation and client generation.
HybridCache for Optimal Performance
csharp
// Program.cs
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Caching.StackExchangeRedis;
builder.Services.AddStackExchangeRedisCache(options =>
options.Configuration = builder.Configuration.GetConnectionString("Redis"));
builder.Services.AddMemoryCache();
builder.Services.AddHybridCache();
// Controller usage
app.MapGet("/api/products", async (IHybridCache cache, IProductRepo repo) =>
{
return await cache.GetOrCreateAsync("products:all",
async _ => await repo.GetAllAsync(),
TimeSpan.FromSeconds(30));
});
HybridCache combines in-memory and distributed caching strategies for optimal performance.
Optimized Static Asset Delivery
csharp
// Serve optimized static assets
app.MapStaticAssets();
MapStaticAssets() provides build-time compression, content-based ETags, and fingerprinting for optimal static file delivery.
Security Best Practices
Authentication and Authorization
csharp
// JWT Authentication setup
builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(options => {
options.Authority = builder.Configuration["Auth:Authority"];
options.Audience = builder.Configuration["Auth:Audience"];
options.RequireHttpsMetadata = true;
});
// CORS policy
builder.Services.AddCors(options =>
options.AddPolicy("frontend", policy =>
policy.WithOrigins("https://yourdomain.com")
.AllowAnyHeader()
.AllowAnyMethod()));
Content Security Policy
Implement CSP headers to restrict script execution sources and prevent XSS attacks.
Input Validation and Sanitization
csharp
// Model validation
public record ProductDto(
[Required] string Name,
[Range(0, 1000)] decimal Price);
Lever Angular's DOM sanitization and .NET's model validation to protect against injection attacks.
Performance Optimization Checklist
Front-End (Angular)
- Use AOT compilation and tree-shaking
- Implement lazy loading for routes
- Leverage signals for fine-grained reactivity
- Enable zoneless change detection
- Utilize httpResource for efficient data fetching
- Implement incremental hydration for SSR
Back-End (.NET 9)
- Use Native AOT for reduced startup time
- Implement HybridCache for frequently accessed data
- Enable response compression
- Use EF Core performance improvements in .NET 9
- Implement health checks and monitoring
Development and Maintenance
CI/CD Pipeline
- Generate OpenAPI documentation during build
- Run contract tests to ensure API consistency
- Use Angular's build optimizer and .NET's publish optimizations
- Implement security scanning in the pipeline
Observability
csharp
// OpenTelemetry setup
builder.Services.AddOpenTelemetry()
.WithMetrics(metrics => metrics
.AddAspNetCoreInstrumentation()
.AddHttpClientInstrumentation())
.WithTracing(tracing => tracing
.AddAspNetCoreInstrumentation()
.AddHttpClientInstrumentation());
Implement comprehensive logging, metrics, and tracing using OpenTelemetry for end-to-end observability.
Conclusion
The combination of Angular v20 and .NET 9 provides a powerful foundation for building high-performance, secure, and maintainable web applications. By leveraging the latest features such as signals, zoneless change detection, Native AOT, and HybridCache, developers can create applications that excel in performance while maintaining excellent developer experience.
Remember to:
- Follow security best practices for both front-end and back-end
- Implement comprehensive monitoring and observability
- Use contract-first development with OpenAPI
- Optimize deployment strategy based on your specific needs
This powerful combination enables teams to deliver exceptional user experiences while maintaining high development velocity.
By implementing these patterns and leveraging the latest features of both frameworks, you can build applications that are not only performant and secure but also maintainable and scalable as your project grows.
Top comments (0)