This instance effectively explains my downside.
I’ve received two lessons, Bill and InvoiceRow; an Bill hosts a group of InvoiceRow.
This classical strucutre is mapped in the identical method within the database, so there may be an INVOICES desk and an INVOICEROWS tables with a one-to-many relationship.
I am utilizing EFCore as O/RM and as a consequence of strict correspondance of the lessons and the realted tables, I made a decision to make use of Lively File, that’s (so far as I perceive) a single class that does each knowledge entry and area logic.
So I added area logic to my lessons. Principally Bill has a static methodology that hundreds it with its rows (relying for this on the EF performance). Then I’ve received validation logic, some calculated subject. Say that every time an InvoiceRow will get modified the Bill complete will get modified too.
Than a Save methodology performs extra validation and calls EF strategies to persist the Bill and its rows as an entire.
It is a quite simple area logic that permits solely a sure method of manipulating the item, that could be a good encapsulation of which I am fairly glad.
Now I need to present a listing of the invoices, for looking or for choosing and processing or no matter.
It is a fundamental requirement, a quite common request that it isn’t very enterprise or area particular.
Seems that the logic that I carried out into Bill will get in the best way. Now I solely want ‘headers’ of the Bill, for certain I do not need to load all of the rows simply to indicate the person the record and permit her to choose one.
After all I might type of disable the loading extra knowledge, however that will imply having ‘two modes’ of working of my class. Even when there are good methods of loading associated file rows solely when wanted, and this alleviate a number of the ache, this class with two distinct modes of woring smells of trickery and appears not very SRP.
The opposite method is saying okay: I would like each ‘evoluted’ entry to the item as full-fledged area objects and to row-level knowledge.
Which means to resign to the compactness of energetic file and resort to a Area mannequin object (is that this the identify?) and a Row Knowledge Gateway (Fowler’s identify), that’s, in different phrases a easy Knowledge Entry object (totally different identify for a similar factor?) that it is my EF entity, does not comprise any enterprise logic, so I can use it the place I do not want validation and loading of associated entities.
Sadly, when describing Row Knowledge Gateway Fowler does not discuss this utilization of this sample, and that makes me doubt if I am heading in the right direction.
Is admittedly this the aim of the info entry layer? If not, what’s the proper place as an alternative? Possibly its too advanced for such a straightforward job, however for the sake of the architectural pattenr I wish to perceive when this piece suits.
I see this downside so typically that I believe there must be a easy but commonplace resolution. Is there one other parctical option to remedy this?