Onion Architecture talks about separating the UI, Service, and Data Layers. All the samples usually given for this involve a single deployment model of the application. For example in .net most of the samples are

Web - MVC app
Core/Domain - Simple class library
Data - Entity Framework

What happens if my application has multiple deployment flavors? For example Azure resources versus On premise SQL Server. Does the solution break down into shareable projects? What happens when pieces of the infrastructure are shared?

Host - On-Premise - has the Program.cs and Startup class only, wires up all the dependencies. Also has logic to do migration/setup for infrastructure
Host - Azure - same as above

Web - Controllers, View, Models - but it class library not an app
Core/Domain - Doesn't change
Infrastructure - SQL
Infrastructure - Azure
Infrastructure - X

Is this correct thinking? should the "App Hosts" be as minimal as possible and wire everything up? Should infrastructures be separated by the infrastructure they are utilizing or the deployment style (On premise vs Azure)? Is it strange to have an infrastructure layer not implement all the repositories defined in domain layer?

  • Clarifying question: When you say "Infrastructure - SQL, Infrastructure - Azure, Infrastructure - X" are you saying that one application had three different data stores at the same time? Or are you saying that the application can be run on three different types of datastores? – aridlehoover Dec 22 '18 at 6:59

What happens if my application has multiple deployment flavors?

You have a layer that deals with that flavor. Whatever it is. That layer should successfully abstract that flavor from the rest of you application. It should encapsulate your app. If it does this successfully the rest of the app has no idea what the flavor of the moment is.

You do this by building an API driven by your apps needs. Not what Azure tried to sell you. So long as whatever the flavor of the month is can satisfy those needs the app doesn't care what it is.

Keep the API small and you'll be able find many flavors that suit your needs and be able to switch at any time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.