The Ports and Adapters architecture aims at building decoupled code. The Domain layer does not depend on the Infrastructure layer directly, instead it depends on the port (the interface) and the implementation of the port is in the Infrastructure layer, right?
My folder structure will be as such:
A project for my UI
A project for the core of the application, which contains Application Service, Domain Services and Domain Models.
A project for the ports: It contains strictly interfaces.
A project for the infrastructure, and I have a persistence folder in there.
The delivery mechanism can be switched (from console app to web app...) and the Core will still work the same.
Same for the infrastructure, I could be using entity framework for once and then switch to dapper without causing a change in the Core.
So far so good, or did I miss something along the way, or did I miss the very basic understanding of the architecture?
Now code wise:
If I have a console app where I have to type a command and it creates a customer.
A class from the Application Service found in the Core project. It uses dependency injection to access the implementation of IPersistence.
public class AddNewCustomer
{
private readonly IPersistence _persistence;
public AddNewCustomer(IPersistence persistence)
{
_persistence = persistence;
}
public bool addToDb(customer customer)
{
return _persistence.add(customer);
}
}
The interface in the port project.
public interface IPersistence
{
bool add(Customer customer);
}
The implementation in the interface project.
public class Persistence: IPersistence
{
public bool add(customer customer)
{
//inserts into DB
}
}
Is the port project supposed to be strictly about interfaces? How do you structure (folder structure) your ports and adapters project?