Skip to content

rafaeldalsenter/dotnet-anticorruptionlayer-sample

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dotnet-anticorruptionlayer-sample

Example of using the anti-corruption layer pattern

Is this project, it's illustrated how to use this pattern to avoid corrupting the Application (or Domain) layer with changes external projects.

Application context

The Application has a UseCase corresponding to buy a book Operation. The first thing to get is detailed information about this book, through an external project (Api.BookInfo.Legacy). The interface to this external service requires the code used to be a string.



The Api.BookInfo.Legacy API will be discontinued, a new API called Api.BookInfo.New will have to be used. This API uses integer type code to identify books. So that this change does not affect the Application layer, an intermediate project (BookInfo.AntiCorruptionLayer) was created, responsible for "translating the code" to the new format (integer type):

Run

To execute the project, a Console application was created where the execution is printed in a terminal. In DI you can choose to use the new API (with the anti-corruption layer) and the old one:

var services = new ServiceCollection()
    .AddBuyBookUseCase()
    .AddBuyBookOutputPort()
    .AddBookInfoAcl(); // <- new API (with anti-corruption layer)
//.AddBookInfoLegacy();   <- Legacy API

References

About

Example of using the anti-corruption layer pattern

Topics

Resources

Stars

Watchers

Forks

Languages