I am trying to figure out how to translate the onion architecture into an ASP.NET Core WebAPI solution, this is what I ended up with:
Let's say I have an application that takes a file path / uri into input whether via a Console application or a WebAPI application, read each line and if some business rules are met change the line to a given business specific format and if not return an error as the new line. The application in both Console and WebAPI must be able to return the output (modified lines with new formats as well as the errors which both match a given class (ValueObject?) to Json and Xml.
Application.Console
: a simple CLI that can consume aApplication.Console.Tests
: testing the CLIApplication.WebApi
: exposing theApplication.WebApi.Tests
:Domain
Domain.Tests
What I am struggling and not sure with:
I would have expected to have an
Infrastructure
+Infrastructure.Tests
but since I don't really have the necessity to use a Database / EF Core atm, I think it's useless, unless I put the configuration of the Swagger / Swashbuckle + Logging configuration into that Infrastructure layer, but I am not sure this is where it belongs.I don't really know where to put the file IO reading part into the
Infrastructure
layer or into anotherApplication.Core
, obviously this layer would rely on the domain one and be consumed by both applications.For some reasons I think that if both applications need the same output formats, then it's better than the formatting part is implemented in something common instead of performing the same sort of action in both
Application.Console
andApplication.WebApi
(even though they would be performed ""differently"" on the surface:- The Console project will consume directly Newtonsoft JSON or the
XmlSerializer
(or another XML serialization library). - The WebApi will leverage the builtin formatters: https://docs.microsoft.com/en-us/aspnet/core/web-api/advanced/formatting?view=aspnetcore-2.1#configuring-formatters
- The Console project will consume directly Newtonsoft JSON or the
Finally I see in some other projects that the controllers which are typically in the WebApi part are sometimes moved to a dedicated project. I am not really sure whether it makes much sense when there is 1 Controller + 1 Action in the whole solution. So that the
Program.cs
andStartup.cs
will be in an Host project. It might be a bit overkilled except if I want to have my tests to be obviously attached to that project (MyProjectName
/MyProjectName.Tests
) and integration tests (using Tester: https://docs.microsoft.com/en-us/aspnet/core/test/integration-tests?view=aspnetcore-2.1) attached to the host (not sure it makes that much sense though)