Iterative building of domain graph in the view(s) vs.single creation of domain graph in the view(s)

13 views
Skip to first unread message

mardo

unread,
Feb 12, 2013, 4:51:22 PM2/12/13
to sharp...@googlegroups.com
I've always been stuck on a situation on how to handle child domain objects of objects when editing in a view using an ORM like NHib.

For example, lets say you have a company and a company has many users.

It makes sense in a lot of cases to allow admin to manage the company information and the users on the same view.

This is the only approach I can think of is allow the user to enter a description of the company and create the object and then go to the view screen (with a companyId and object persisted) so I now have a real company object to add users to.

This leaves a bad case of forcing a var c = new Company("Acme") and then adding users to to he object later through other views even though the domain model NEEDS users to be good in the domain.

I'm looking for something where I can take them to the view and build out the entire object tree and then create a new company and it associated users in one fell swoop.

Something like this.

var c= new Company("Acme",users);

I hope that makes sense.  What I am really trying to do here is build out the entire object graph in the view and then persistent vs. incrementally building out a object that might not be good if the user leaves the screen and a company was created without users.

Would be great to get your opinions, hope that makes sense.

Thanks,
Marty









mardo

unread,
Feb 13, 2013, 11:07:38 AM2/13/13
to sharp...@googlegroups.com

It appears this is the job of the task class.  You would have view object encapsulating all the objects that are needed and then you can pull the objects together in the task, validate, map then persist them.

Found this in the CaTs example:

    public ActionConfirmation<SupportTicket> Open(SupportTicketFormDto supportTicketFormDto) {
            if (supportTicketFormDto == null) throw new ArgumentNullException("supportTicketFormDto is null");
            if (!DataAnnotationsValidator.TryValidate(supportTicketFormDto))
                throw new InvalidOperationException("supportTicketFormDto is in an invalid state");

            var supportTicketToSave = supportTicketFormDto.Id > 0
                ? _supportTicketRepository.Get(supportTicketFormDto.Id)
                : CreateNewSupportTicket(supportTicketFormDto);

            TransferFormValuesTo(supportTicketToSave, supportTicketFormDto);

            var customerConfirmationMessage = HandleNewCustomer(supportTicketFormDto.NewCustomer, supportTicketToSave);
            var issueConfirmationMessage = HandleNewIssueType(supportTicketFormDto.NewIssueType, supportTicketToSave);
            _supportTicketRepository.SaveOrUpdate(supportTicketToSave);

            return ActionConfirmation<SupportTicket>
                .CreateSuccessConfirmation("Support ticket #" + supportTicketToSave.Id + " has been opened." +
                    customerConfirmationMessage + issueConfirmationMessage, supportTicketToSave);
Reply all
Reply to author
Forward
0 new messages