Reputation: 759
Sometimes it happens that you have to consume services from third party, if you want to use api of facebook or twitter. Then we have to create various wrapper classes which calls functions of external api with required parameters and return the required result.
My question is where to put this wrapper classes, in App Layer itself and create a service class which call functions of wrapper classes or in separate class library in Infrastructure layer ?
Do I put wrapper classes in INFRA LAYER or in APP LAYER ?
Upvotes: 2
Views: 1425
Reputation: 2528
What you are essentially trying to do here is write an anti-corruption layer. In other words you are trying to protect your inner domain from external influences.
There are many ways to do this but essentially you most keep your domain integral. What we would do is define a "contract" (i.e. interface) that defines what your domain object is generically. This interface is what is used everywhere in your domain.
Then you have anti-corruption layer code (i.e. the wrapper classes that you mention). We keep these wrapper classes in an assembly called WhateverPrefix.AntiCorruptionLayer. The wrappers implement the "contract" defined in the domain. The domain does not reference the anti-corruption layer assembly, however the anti-corruption layer assembly does reference the domain.
In the anti-corruption layer assembly itself, we would usually dedicate a specific descriptive folder at its root per anti-corruption layer.
This stuff is not an exact science, Im just outlining one of the ways I have seen this stuff being done in my experience. Hope this helps...
Upvotes: 2