I just read the book 'clean architecture' by Uncle Bob and really like the approach. But the big disappointment came when I tried to implement it in C#. I really hope you can help me with some questions.
What I tried was to implement the following component diagram:
A = Enterprise Business Rules
B = Application Business Rules
C = Interface Adapters
D = Frameworks & Drivers
But some things seem strange to me:
A presenter converts the "OutputData" (with for example date objects) in "ViewModel" (that has only strings and flags). So the interface "Output Boundary" could have a function "present" with a parameter of type "OutputData" and return a value with type "ViewModel". But Output data is not allowed to have a code reference to "ViewModel", so how should this work?
The outer most layer is the only layer where "Frameworks" are allowed. But in frameworks the "controllers" are usually build into the framework. So do I have to build a wrapper? So I would put controllers of the framework in the outermost layer and my own "architecture controllers" to the adapter layer? Seems like over engineering to me.
If I look at concrete implementations on the web, this does not really answer my questions.
For example this guy created a project with three components:
Web.Api - Maps to the layers that hold the Web, UI and Presenter concerns. In the context of our API, this means it accepts input in the form of http requests over the network (e.g., GET/POST/etc.) and returns its output as content formatted as JSON/HTML/XML, etc. The Presenters contain .NET framework-specific references and types, so they also live here as per The Dependency Rule we don't want to pass any of them inward.
Web.Api.Core - Maps to the layers that hold the Use Case and Entity concerns and is also where our External Interfaces get defined. These innermost layers contain our domain objects and business rules. The code in this layer is mostly pure C# - no network connections, databases, etc. allowed. Interfaces represent those dependencies, and their implementations get injected into our use cases as we'll see shortly.
Web.Api.Infrastructure - Maps to the layers that hold the Database and Gateway concerns. In here, we define data entities, database access (typically in the shape of repositories), integrations with other network services, caches, etc. This project/layer contains the physical implementation of the interfaces defined in our domain layer.
He is not the only one out there having a layer called "infrastructure". But I did not find this layer in the book. Where does it come from? Sometimes people use it for database access, sometimes for services. Where does the term "infrastructure" come from?
He puts "Web, UI and Presenter concerns" in the Web-Layer. So he mixes layers.
On web applications - like an SPA with Angular that accesses an API in the background, I think that my web application should have its own "clean architecture" like described here. My .NET core application on the server also has its own "clean architecture". This makes sense to me. But uncle bob states that "the web is a detail", so this looks like he would treat Angular only as a "detail" and the UI. But probably he did not think of SPAs while he wrote the book... SPAs can have a part of the business rules. So how do you deal with that?