You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, I meet a issue similar to the following code: the controller get a body(string), the conversion from body to domain object(dto object) is very complicated. And both Application layer and Infrastructure layer(repository) reply on the conversion.
// Application LayerpublicrecordDataDto(intId,intI1,doubleD1,stringS1,stringS2,stringS3,stringS4,stringS5);publicrecordDataVm(stringBody);publicrecordGetDataQuery:IRequest<DataVm>{publicintId{get;init;}}publicclassGetDataQueryHandler:IRequestHandler<GetDataQuery,DataVm>{privatereadonlyIDataReposity_dataReposity;publicGetDataQueryHandler(IDataRepositydataReposity){_dataReposity=dataReposity;}publicTask<DataVm>Handle(GetDataQueryrequest,CancellationTokencancellationToken){DataObjectd=_dataReposity.GetDataById(request.Id);DataDtodto=new(d.Id,d.I1,d.D1,d.S1,d.S2,d.S3,d.S4,d.S5);// convert dto to body: Where the conversion code should be placed?stringbody="converted";//DataVmvm=new(body);returnTask.FromResult(vm);}}publicrecordAddDataCommand:IRequest{publicstringBody{get;init;}="";}publicclassAddDataCommandHandler:IRequestHandler<AddDataCommand>{privatereadonlyIDataReposity_dataReposity;publicAddDataCommandHandler(IDataRepositydataReposity){_dataReposity=dataReposity;}publicTask<Unit>Handle(AddDataCommandrequest,CancellationTokencancellationToken){stringbody=request.Body;// convert body to DataObject: Where the conversion code should be placed?DataObjectdataObject=new(1,1,1,"","","","","");returnTask.FromResult(Unit.Value);}}
// Infrastructure layerpublicclassDataReposity:IDataReposity{privatestringGetBodyFromDatabase(intid){// get str body from databsestringbody="";returnbody;}privatevoidSaveBodyToDatabase(intid,stringbody){// save str body from databsereturn;}publicDataObjectGetDataById(intid){stringbody=GetBodyFromDatabase(id);// convert body to DataObject: Where the conversion code should be placed?DataObjectdataObject=new(1,1,1,"","","","","");returndataObject;}publicvoidSaveData(DataObjectdataObject){intid=dataObject.Id;// convert DataObject to body : Where the conversion code should be placed?stringbody="";SaveBodyToDatabase(id,body);}}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Hello, I meet a issue similar to the following code: the controller get a body(string), the conversion from body to domain object(dto object) is very complicated. And both Application layer and Infrastructure layer(repository) reply on the conversion.
I don't know where to put the conversion code.
Need help, thanks!
Domain:
Application Layer:
Beta Was this translation helpful? Give feedback.
All reactions