Skip to content

Instantly share code, notes, and snippets.

View eric-kobby's full-sized avatar
🏠
Working from home

Eric Kobby Mensah eric-kobby

🏠
Working from home
View GitHub Profile

🚀 Clean Strategy Pattern Using Keyed Services in .NET 8

Exporting data in multiple formats like CSV, JSON, or XML is a common requirement in backend systems.

But how do you design that elegantly without falling into a mess of switch statements or service maps?

This post walks you through how to solve that with:

  • The Strategy Pattern
  • .NET 8’s new GetKeyedService<T>() feature
  • Clean and open architecture — easy to extend, maintain, and scale