Socialize

Showing posts with label Angular Standalone Components. Show all posts
Showing posts with label Angular Standalone Components. Show all posts

Thursday, October 16, 2025

🌐 Building a Modern Web Application Using .NET Core Web API and Angular with Standalone Components

 🚀 Introduction

Modern web development has evolved rapidly, and developers today look for frameworks that are scalable, modular, and high-performing.
A perfect combination that fulfills these needs is .NET Core Web API for the backend and Angular (15+) with Standalone Components for the frontend.

This article walks you through how to use both technologies together to build a clean, fast, and maintainable web application.


🧩 Architecture Overview

LayerTechnologyDescription
Frontend (Client)Angular 15+ (Standalone Components)Manages UI, routing, and communication with the backend using HTTP services.
Backend (Server).NET 6/7/8 Web APIProvides REST APIs, authentication, and business logic.
DatabaseSQL Server / PostgreSQL / Azure SQLStores persistent application data.
HostingAzure App Service / Docker / IISHosts both the backend and frontend applications.

🅰️ Angular with Standalone Components

What Are Standalone Components?

From Angular 15 onwards, you no longer need to wrap every component inside an NgModule.
Standalone Components simplify your app’s structure, reduce boilerplate code, and improve performance.

Create a new Angular app with standalone components:

ng new my-app --standalone

Example of a simple standalone component:

import { Component } from '@angular/core'; @Component({ selector: 'app-home', standalone: true, template: `<h1>Welcome to My Angular App!</h1>` }) export class HomeComponent {}

You can import other modules or components directly:

import { CommonModule } from '@angular/common'; import { FormsModule } from '@angular/forms'; @Component({ selector: 'app-user', standalone: true, imports: [CommonModule, FormsModule], templateUrl: './user.component.html' }) export class UserComponent {}

Routing with Standalone Components

import { Routes } from '@angular/router'; import { HomeComponent } from './home.component'; import { UserComponent } from './user.component'; export const routes: Routes = [ { path: '', component: HomeComponent }, { path: 'user', component: UserComponent } ];

Bootstrap the app without modules:

bootstrapApplication(AppComponent, { providers: [provideRouter(routes)] });

⚙️ Backend Setup — .NET Core Web API

Create a new API project:

dotnet new webapi -n MyApp.Api

Example Controller:

using Microsoft.AspNetCore.Mvc; [ApiController] [Route("api/[controller]")] public class UsersController : ControllerBase { [HttpGet] public IActionResult GetUsers() => Ok(new[] { new { Id = 1, Name = "Cherry" } }); }

Enable CORS for Angular

To allow the Angular frontend to call the API:

builder.Services.AddCors(options => { options.AddPolicy("AllowAngular", policy => policy.WithOrigins("http://localhost:4200") .AllowAnyHeader() .AllowAnyMethod()); }); var app = builder.Build(); app.UseCors("AllowAngular"); app.MapControllers(); app.Run();

🔗 Connecting Angular with .NET Core Web API

In Angular, use the HttpClient service to connect to your API.

import { HttpClient } from '@angular/common/http'; import { Component, inject } from '@angular/core'; @Component({ selector: 'app-users', standalone: true, template: ` <ul> <li *ngFor="let user of users">{{ user.name }}</li> </ul> ` }) export class UsersComponent { private http = inject(HttpClient); users: any[] = []; ngOnInit() { this.http.get<any[]>('https://localhost:7200/api/users') .subscribe(data => this.users = data); } }

📦 Folder Structure Example

/MyApp ├── /MyApp.Api (ASP.NET Core Web API) ├── Controllers/ └── Models/ ├── /MyApp.Client (Angular App with Standalone Components) ├── src/app/ └── environments/ └── docker-compose.yml (optional for containers)

⚙️ Deployment & CI/CD

You can deploy both apps on Azure using:

  • Azure App Service for backend API

  • Azure Static Web Apps or App Service for frontend

  • GitHub Actions / Azure DevOps for automated CI/CD pipelines

This setup ensures smooth builds, testing, and deployment.


💡 Advantages of This Stack

FeatureBenefit
No NgModulesSimpler and cleaner architecture
Tree-shakable ImportsSmaller and faster bundles
.NET Core Web APICross-platform, fast, and secure backend
ScalableEasily expandable for microservices
Great DevOps SupportWorks seamlessly with Azure and GitHub

🧠 Conclusion

Using .NET Core Web API with Angular Standalone Components provides a modern, high-performance, and scalable way to build full-stack web applications.
This architecture simplifies development, improves code maintainability, and offers better deployment flexibility — perfect for enterprise and startup projects alike.

Blog Archive

Don't Copy

Protected by Copyscape Online Plagiarism Checker

Pages