Skip to main content

Command Palette

Search for a command to run...

๐— ๐—ฎ๐˜€๐˜๐—ฒ๐—ฟ๐—ถ๐—ป๐—ด ๐——๐—ฒ๐—ฝ๐—ฒ๐—ป๐—ฑ๐—ฒ๐—ป๐—ฐ๐˜† ๐—œ๐—ป๐—ท๐—ฒ๐—ฐ๐˜๐—ถ๐—ผ๐—ป & ๐——๐—ฒ๐—ฝ๐—ฒ๐—ป๐—ฑ๐—ฒ๐—ป๐—ฐ๐˜† ๐—œ๐—ป๐˜ƒ๐—ฒ๐—ฟ๐˜€๐—ถ๐—ผ๐—ป ๐—ถ๐—ป ๐—”๐—ฆ๐—ฃ.๐—ก๐—˜๐—ง ๐—–๐—ผ๐—ฟ๐—ฒ โ€“ Quick Guide

Published
โ€ข1 min readโ€ขView as Markdown

Are you building scalable, testable applications in ASP.NET Core? Then you must embrace the ๐——๐—ฒ๐—ฝ๐—ฒ๐—ป๐—ฑ๐—ฒ๐—ป๐—ฐ๐˜† ๐—œ๐—ป๐˜ƒ๐—ฒ๐—ฟ๐˜€๐—ถ๐—ผ๐—ป ๐—ฃ๐—ฟ๐—ถ๐—ป๐—ฐ๐—ถ๐—ฝ๐—น๐—ฒ (๐——๐—œ๐—ฃ) and implement it using ๐——๐—ฒ๐—ฝ๐—ฒ๐—ป๐—ฑ๐—ฒ๐—ป๐—ฐ๐˜† ๐—œ๐—ป๐—ท๐—ฒ๐—ฐ๐˜๐—ถ๐—ผ๐—ป (๐——๐—œ).

Hereโ€™s a simple, clear example to help you understand how both work together in a real ASP.NET Core project. ๐Ÿš€

๐Ÿ”น Step 1: Define an Interface and Implementation (DIP)

public interface IMessageService { string GetMessage(); }

public class HelloMessageService : IMessageService { public string GetMessage() { return "Hello from the message service!"; } }

๐Ÿ’ก Your controller now depends on an abstraction (interface) โ€“ this is ๐——๐—ฒ๐—ฝ๐—ฒ๐—ป๐—ฑ๐—ฒ๐—ป๐—ฐ๐˜† ๐—œ๐—ป๐˜ƒ๐—ฒ๐—ฟ๐˜€๐—ถ๐—ผ๐—ป ๐—ฃ๐—ฟ๐—ถ๐—ป๐—ฐ๐—ถ๐—ฝ๐—น๐—ฒ in action.

๐Ÿ”ธ Step 2: Inject the Dependency into the Controller (DI)

public class MessageController : ControllerBase { private readonly IMessageService _messageService;

public MessageController(IMessageService messageService) { _messageService = messageService; }

public IActionResult Get() { return Ok(_messageService.GetMessage()); } }

This is ๐—ฐ๐—ผ๐—ป๐˜€๐˜๐—ฟ๐˜‚๐—ฐ๐˜๐—ผ๐—ฟ ๐—ถ๐—ป๐—ท๐—ฒ๐—ฐ๐˜๐—ถ๐—ผ๐—ป, one of the most common forms of ๐——๐—ฒ๐—ฝ๐—ฒ๐—ป๐—ฑ๐—ฒ๐—ป๐—ฐ๐˜† ๐—œ๐—ป๐—ท๐—ฒ๐—ฐ๐˜๐—ถ๐—ผ๐—ป in ASP.NET Core.

๐Ÿ”น Step 3: Register the Service in Program.cs

builder.Services.AddScoped<IMessageService, HelloMessageService>();

Now your service is automatically injected by the .๐—ก๐—˜๐—ง ๐—–๐—ผ๐—ฟ๐—ฒ ๐—ฏ๐˜‚๐—ถ๐—น๐˜-๐—ถ๐—ป ๐——๐—œ ๐—ฐ๐—ผ๐—ป๐˜๐—ฎ๐—ถ๐—ป๐—ฒ๐—ฟ.

When /message is called, the controller gets its dependency injected from the container. No tight coupling. Easy to test. Clean architecture. ๐Ÿ’ช

๐Ÿ’ฌ ๐—›๐—ฎ๐˜ƒ๐—ฒ ๐˜†๐—ผ๐˜‚ ๐—ถ๐—บ๐—ฝ๐—น๐—ฒ๐—บ๐—ฒ๐—ป๐˜๐—ฒ๐—ฑ ๐—บ๐˜‚๐—น๐˜๐—ถ๐—ฝ๐—น๐—ฒ ๐˜€๐—ฒ๐—ฟ๐˜ƒ๐—ถ๐—ฐ๐—ฒ ๐—ถ๐—บ๐—ฝ๐—น๐—ฒ๐—บ๐—ฒ๐—ป๐˜๐—ฎ๐˜๐—ถ๐—ผ๐—ป๐˜€ ๐—ผ๐—ฟ ๐˜‚๐˜€๐—ฒ๐—ฑ ๐—บ๐—ผ๐—ฐ๐—ธ ๐˜€๐—ฒ๐—ฟ๐˜ƒ๐—ถ๐—ฐ๐—ฒ๐˜€ ๐—ณ๐—ผ๐—ฟ ๐˜๐—ฒ๐˜€๐˜๐—ถ๐—ป๐—ด ๐˜„๐—ถ๐˜๐—ต ๐——๐—œ ๐—ถ๐—ป ๐˜†๐—ผ๐˜‚๐—ฟ ๐—ฝ๐—ฟ๐—ผ๐—ท๐—ฒ๐—ฐ๐˜? ๐—ช๐—ผ๐˜‚๐—น๐—ฑ ๐—น๐—ผ๐˜ƒ๐—ฒ ๐˜๐—ผ ๐—ต๐—ฒ๐—ฎ๐—ฟ ๐—ต๐—ผ๐˜„ ๐˜†๐—ผ๐˜‚ ๐˜€๐˜๐—ฟ๐˜‚๐—ฐ๐˜๐˜‚๐—ฟ๐—ฒ๐—ฑ ๐—ถ๐˜! ๐Ÿ‘‡

More from this blog

๐—ฃ๐—ฎ๐˜€๐˜€๐˜„๐—ผ๐—ฟ๐—ฑ๐—น๐—ฒ๐˜€๐˜€ ๐—”๐˜‚๐˜๐—ต๐—ฒ๐—ป๐˜๐—ถ๐—ฐ๐—ฎ๐˜๐—ถ๐—ผ๐—ป ๐—ฅ๐—ฒ๐˜ƒ๐—ผ๐—น๐˜‚๐˜๐—ถ๐—ผ๐—ป

Passwords are the weakest link โ€” and .NET 10 just made it easier to remove them. With built-in support for passkeys and WebAuthn, you can authenticate users securely without storing a single password. .NET 10 introduces native passwordless authentica...

Nov 4, 20251 min read

.๐—ก๐—˜๐—ง ๐Ÿญ๐Ÿฌ ๐— ๐—ฎ๐—ธ๐—ฒ๐˜€ ๐—Ÿ๐—˜๐—™๐—ง & ๐—ฅ๐—œ๐—š๐—›๐—ง ๐—๐—ผ๐—ถ๐—ป๐˜€ ๐—˜๐—ฎ๐˜€๐—ถ๐—ฒ๐—ฟ ๐—ง๐—ต๐—ฎ๐—ป ๐—˜๐˜ƒ๐—ฒ๐—ฟ!

If youโ€™ve ever struggled to write complex LEFT JOINs in LINQ, youโ€™ll love whatโ€™s coming in .NET 10. No more juggling SelectMany, GroupJoin, and DefaultIfEmpty โ€” Microsoft just made it clean, readable, and developer-friendly! In .NET 10, LINQ gets fir...

Nov 1, 20251 min read

๐Ÿ”ฅ .๐—ก๐—˜๐—ง ๐—™๐—ฟ๐—ฎ๐—บ๐—ฒ๐˜„๐—ผ๐—ฟ๐—ธ ๐˜ƒ๐˜€ .๐—ก๐—˜๐—ง ๐—–๐—ผ๐—ฟ๐—ฒ โ€” ๐—ž๐—ฒ๐˜† ๐——๐—ถ๐—ณ๐—ณ๐—ฒ๐—ฟ๐—ฒ๐—ป๐—ฐ๐—ฒ๐˜€ ๐—˜๐˜…๐—ฝ๐—น๐—ฎ๐—ถ๐—ป๐—ฒ๐—ฑ

If youโ€™re preparing for a .NET developer interview, this is one question you canโ€™t afford to miss! Letโ€™s break down the core differences that every developer should know ๐Ÿ‘‡ 1๏ธโƒฃ Platform Support โ€“ .NET Framework works only on Windows, while .NET Core ...

Oct 30, 20252 min read

๐—˜๐—ฎ๐—ด๐—ฒ๐—ฟ ๐˜ƒ๐˜€ ๐—Ÿ๐—ฎ๐˜‡๐˜† ๐—Ÿ๐—ผ๐—ฎ๐—ฑ๐—ถ๐—ป๐—ด

In ๐—˜๐—ป๐˜๐—ถ๐˜๐˜† ๐—™๐—ฟ๐—ฎ๐—บ๐—ฒ๐˜„๐—ผ๐—ฟ๐—ธ ๐—–๐—ผ๐—ฟ๐—ฒ, how and when related data is fetched matters โ€” thatโ€™s where ๐—˜๐—ฎ๐—ด๐—ฒ๐—ฟ ๐—Ÿ๐—ผ๐—ฎ๐—ฑ๐—ถ๐—ป๐—ด and ๐—Ÿ๐—ฎ๐˜‡๐˜† ๐—Ÿ๐—ผ๐—ฎ๐—ฑ๐—ถ๐—ป๐—ด come in. ๐—˜๐—ฎ๐—ด๐—ฒ๐—ฟ ๐—Ÿ๐—ผ๐—ฎ๐—ฑ๐—ถ๐—ป๐—ด means related data is loaded immediately with the main e...

Oct 29, 20251 min read

Visual Studio Updates

89 posts