Menu

1 / 2

Anti-Corruption Layer in .NET: Protecting Your Domain from External APIs

DEV Community: csharp·Adrián Bailador·7 months ago
#SPzPDmyM
#dev#class#code#domain#article
Reading 0:00
15s threshold

We had a clean domain. Orders, customers, payments — all modelled carefully, all speaking the same language. Then we integrated with a payment provider.

Six months later, the PaymentStatus enum had values like PSPCONFIRMED , PSPREJECTED_RETRY , and AUTHORISED_3DS . Our Order entity had a StripeChargeId field. Our service layer was calling MapFromStripeWebhookPayload() . And every developer who touched payments had to understand Stripe's object model before they could understand ours.

The domain hadn't changed. But it had been contaminated.

The Anti-Corruption Layer is the pattern that prevents this. Here's how it works and how to implement it in .NET.

What Is the Anti-Corruption Layer?

The term comes from Eric Evans' Domain-Driven Design . When two systems need to communicate, the boundary between them is dangerous.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.