Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

Post History

75%
+4 −0
Q&A Dealing with code maintenance when saving a large and complex entity in a single business transaction

Context I am currently working on migrating a legacy application to an ASP.NET Core + Angular application. The Web API's main project is based on Jason Taylor's template (clean architecture) and a...

1 answer  ·  posted 1y ago by Alexei‭  ·  last activity 1y ago by r~~‭

#3: Nominated for promotion by user avatar Alexei‭ · 2022-12-25T09:48:45Z (over 1 year ago)
#2: Post edited by user avatar Alexei‭ · 2022-12-23T14:38:47Z (over 1 year ago)
added drawing tool reference
  • ## Context
  • I am currently working on migrating a legacy application to an ASP.NET Core + Angular application. The Web API's main project is based on [Jason Taylor's template](https://github.com/jasontaylordev/CleanArchitecture) (clean architecture) and among others relies on [MediatR library](https://github.com/jbogard/MediatR).
  • The UI/UX experience for already migrated business flows relies on UI pages that look like the following:
  • ![Existing UI/UX for reading and editing data](https://software.codidact.com/uploads/nsiw5fuh3qxc3aa2wc68irxn3njx)
  • When the user enters a page, each section (group) is loading its data, which ultimately relies on a MediatR query. Only the information from a specific group can be edited and saved. This helps our development and maintenance quite a lot:
  • - data fetch is clearly separated for each part (component)
  • - a good mapping between use cases and code structure (data fetch for a part = query, save group data = command)
  • - smaller transactions (save small data, instead of bigger data)
  • - each use case implementation is quite small and easy to maintain
  • Now, for migrating the functionality around another entity type, the product owner wants another approach to UI/UX that looks like the following:
  • ![Desired UI/UX for reading and editing data](https://software.codidact.com/uploads/s7s0t9u0ftxcxwpe17pzm9t6bki2)
  • - there is no read-only view and the users can directly jump at editing stuff
  • - there is the main Save button that will save "everything". We can have Save working only on the current section to keep things more manageable.
  • - at least one section is quite heavy (dozens of fields and files to be uploaded)
  • ## The Issue
  • The main issue with the desired design is that the number of use cases is drastically reduced and I get way bigger and more complex payloads to handle.
  • The legacy application treats the saving functionality in a rather monolithic way resulting in a very hard-to-maintain code.
  • I am wondering about how to tackle this issue as I want to avoid maintenance issues.
  • ## Possible Solution
  • Since I cannot avoid a big payload being ingested in the API, I need to somehow split the business logic into more maintainable pieces of code. Chain of Responsibility pattern comes into my mind:
  • - controller action received the payload
  • - a save command is issued with the big payload
  • - a bunch of middleware will receive the payload and each one will only process the part of interest (e.g. merging the section 1/group 1 data). I can even have the payload DTO implement an interface dedicated to each processing part (I will have to check if it works).
  • - the final middleware will commit the transaction if everything goes fine until then
  • We are already using the concept for handling cross-cutting concerns in a way similar to what is depicted in [this article](https://arturkrajewski.silvrback.com/chain-of-responsibility-pattern-for-handling-cross-cutting-concerns), but I have used for handling business transactions.
  • Is this a good approach for handling such a business scenario?
  • ## Context
  • I am currently working on migrating a legacy application to an ASP.NET Core + Angular application. The Web API's main project is based on [Jason Taylor's template](https://github.com/jasontaylordev/CleanArchitecture) (clean architecture) and among others relies on [MediatR library](https://github.com/jbogard/MediatR).
  • The UI/UX experience for already migrated business flows relies on UI pages that look like the following:
  • ![Existing UI/UX for reading and editing data](https://software.codidact.com/uploads/nsiw5fuh3qxc3aa2wc68irxn3njx)
  • When the user enters a page, each section (group) is loading its data, which ultimately relies on a MediatR query. Only the information from a specific group can be edited and saved. This helps our development and maintenance quite a lot:
  • - data fetch is clearly separated for each part (component)
  • - a good mapping between use cases and code structure (data fetch for a part = query, save group data = command)
  • - smaller transactions (save small data, instead of bigger data)
  • - each use case implementation is quite small and easy to maintain
  • Now, for migrating the functionality around another entity type, the product owner wants another approach to UI/UX that looks like the following:
  • ![Desired UI/UX for reading and editing data](https://software.codidact.com/uploads/s7s0t9u0ftxcxwpe17pzm9t6bki2)
  • - there is no read-only view and the users can directly jump at editing stuff
  • - there is the main Save button that will save "everything". We can have Save working only on the current section to keep things more manageable.
  • - at least one section is quite heavy (dozens of fields and files to be uploaded)
  • ## The Issue
  • The main issue with the desired design is that the number of use cases is drastically reduced and I get way bigger and more complex payloads to handle.
  • The legacy application treats the saving functionality in a rather monolithic way resulting in a very hard-to-maintain code.
  • I am wondering about how to tackle this issue as I want to avoid maintenance issues.
  • ## Possible Solution
  • Since I cannot avoid a big payload being ingested in the API, I need to somehow split the business logic into more maintainable pieces of code. Chain of Responsibility pattern comes into my mind:
  • - controller action received the payload
  • - a save command is issued with the big payload
  • - a bunch of middleware will receive the payload and each one will only process the part of interest (e.g. merging the section 1/group 1 data). I can even have the payload DTO implement an interface dedicated to each processing part (I will have to check if it works).
  • - the final middleware will commit the transaction if everything goes fine until then
  • We are already using the concept for handling cross-cutting concerns in a way similar to what is depicted in [this article](https://arturkrajewski.silvrback.com/chain-of-responsibility-pattern-for-handling-cross-cutting-concerns), but I have used for handling business transactions.
  • **Is this a good approach for handling such a business scenario?
  • **
  • Note: drawings were done using [Excalidraw](https://excalidraw.com/).
#1: Initial revision by user avatar Alexei‭ · 2022-12-23T12:59:54Z (over 1 year ago)
Dealing with code maintenance when saving a large and complex entity in a single business transaction
## Context

I am currently working on migrating a legacy application to an ASP.NET Core + Angular application. The Web API's main project is based on [Jason Taylor's template](https://github.com/jasontaylordev/CleanArchitecture) (clean architecture) and among others relies on [MediatR library](https://github.com/jbogard/MediatR).

The UI/UX experience for already migrated business flows relies on UI pages that look like the following:

![Existing UI/UX for reading and editing data](https://software.codidact.com/uploads/nsiw5fuh3qxc3aa2wc68irxn3njx)

When the user enters a page, each section (group) is loading its data, which ultimately relies on a MediatR query. Only the information from a specific group can be edited and saved. This helps our development and maintenance quite a lot:

- data fetch is clearly separated for each part (component)
- a good mapping between use cases and code structure (data fetch for a part = query, save group data = command)
- smaller transactions (save small data, instead of bigger data)
- each use case implementation is quite small and easy to maintain

Now, for migrating the functionality around another entity type, the product owner wants another approach to UI/UX that looks like the following:

![Desired UI/UX for reading and editing data](https://software.codidact.com/uploads/s7s0t9u0ftxcxwpe17pzm9t6bki2)

- there is no read-only view and the users can directly jump at editing stuff
- there is the main Save button that will save "everything". We can have Save working only on the current section to keep things more manageable. 
- at least one section is quite heavy (dozens of fields and files to be uploaded)

## The Issue

The main issue with the desired design is that the number of use cases is drastically reduced and I get way bigger and more complex payloads to handle.

The legacy application treats the saving functionality in a rather monolithic way resulting in a very hard-to-maintain code.

I am wondering about how to tackle this issue as I want to avoid maintenance issues. 

## Possible Solution

Since I cannot avoid a big payload being ingested in the API, I need to somehow split the business logic into more maintainable pieces of code. Chain of Responsibility pattern comes into my mind:

- controller action received the payload
- a save command is issued with the big payload
- a bunch of middleware will receive the payload and each one will only process the part of interest (e.g. merging the section 1/group 1 data). I can even have the payload DTO implement an interface dedicated to each processing part (I will have to check if it works).
- the final middleware will commit the transaction if everything goes fine until then

We are already using the concept for handling cross-cutting concerns in a way similar to what is depicted in [this article](https://arturkrajewski.silvrback.com/chain-of-responsibility-pattern-for-handling-cross-cutting-concerns), but I have used for handling business transactions.

Is this a good approach for handling such a business scenario?