I'm lurking on your conversation, and reading with interest. Lately, I've
been running into similar problems myself, and like to read other opinions
and solutions, even if not contributing. Easy enough to ignore a thread if
not relevant.

Should you take it offline, can I ask you please to reply your conclusions.

Thanks!

2008/10/7 Stefan Sedich <[EMAIL PROTECTED]>

>
> Amen to that, this is another attempt at designing an application in
> this manner, and I must say I am learning alot, you learn by doing
> these things.
>
> I run into many issues and find it hard sometimes to just give myself
> a sanity check to say that is ok move on. I am happy at this point but
> have a bit to go until I am 100% satisfied. I guess another question
> for you is when mapping a DTO to a domain say an OrderDTO which has a
> collection of OrderItemDTO inside it do you map these children back in
> the mapper? Or just have a AddOrderItem service method.
>
> I know this is the NH forums and I am poluting it with unrelated
> gander, you happy to chat over email?
>
>
> Cheers again.
>
> On Tue, Oct 7, 2008 at 9:18 PM, Gustavo Ringel <[EMAIL PROTECTED]>
> wrote:
> > I like it, but you know...it's a matter of own taste, if you ask everyone
> in
> > the group they will do something different, and different from what they
> > will do in another month...we learn and improve ourselves all the time!
> >
> > Gustavo.
> >
> > On Tue, Oct 7, 2008 at 2:07 PM, Stefan Sedich <[EMAIL PROTECTED]>
> > wrote:
> >>
> >> Apart from that is it looking better?
> >>
> >> Stefan Sedich
> >>
> >> On 07/10/2008, at 7:53 PM, "Gustavo Ringel" <[EMAIL PROTECTED]>
> >> wrote:
> >>
> >> I personally don't like the validate there...I don't see what if it does
> >> not validate for example.
> >>
> >> If you had used NH.Validator, you can get the validation integrated with
> >> the update and then get an exception if it is not valid...
> >>
> >> Gustavo.
> >>
> >> On Tue, Oct 7, 2008 at 1:28 PM, Stefan Sedich <[EMAIL PROTECTED]>
> >> wrote:
> >>>
> >>> Ok refactored my code like so:
> >>>
> >>>  public void Update(AgentUpdateDTO agentUpdateDTO) {
> >>>
> >>>            // Use the assembler to map from the dto using the
> assembler.
> >>>            Agent agent =
> this.agentAssembler.MapFromDTO(agentUpdateDTO);
> >>>
> >>>            // Validate the model and use repository to update.
> >>>            agent.Validate();
> >>>            this.agentRepository.Update(agent);
> >>>
> >>>        }
> >>>
> >>> The agentAssembler is injected into my service by Dependancy injection
> >>> now which works a charm, my assembler has a MapFromDTO method which
> >>> handles the mapping, the assembler itself is injected the required
> >>> repositories to do the mappings the method would look like so:
> >>>
> >>> public override Agent MapFromDTO(AgentUpdateDTO dto) {
> >>>
> >>>            // If id is 0 create a new agent model, otherwise
> >>>            // use repository to select the agent.
> >>>            var agent = (dto.Id == 0)
> >>>                ? new Agent()
> >>>                : this.agentRepository.SelectById(dto.Id);
> >>>
> >>>            // Map across properties from DTO.
> >>>            agent.Enabled = dto.Enabled;
> >>>            agent.FirstName = dto.FirstName;
> >>>            agent.Surname = dto.Surname;
> >>>            agent.UserName = dto.UserName;
> >>>            agent.RowVersion = dto.RowVersion;
> >>>
> >>>            // Map across country if the code is set.
> >>>            if (!string.IsNullOrEmpty(dto.CountryCode))
> >>>                agent.Country =
> >>> this.countryRepository.SelectById(dto.CountryCode);
> >>>
> >>>            // Return the mapped agent model.
> >>>            return agent;
> >>>
> >>>        }
> >>>
> >>>
> >>> Do you find this better than my previous solution or do you have more
> >>> tips for me :), I am pretty happy with the way it is working now
> >>> though.
> >>>
> >>>
> >>> Cheers
> >>>
> >>> On Mon, Oct 6, 2008 at 12:01 AM, Stefan Sedich <
> [EMAIL PROTECTED]>
> >>> wrote:
> >>> > Excellent looks like I am not totally off the rails then :)
> >>> > Cheers
> >>> > Stefan
> >>> >
> >>> > On 05/10/2008, at 10:59 PM, "Gustavo Ringel" <
> [EMAIL PROTECTED]>
> >>> > wrote:
> >>> >
> >>> > I give the translators the access to the repositories they
> >>> > require...(injection)
> >>> >
> >>> > Gustavo.
> >>> >
> >>> > On Sun, Oct 5, 2008 at 4:51 PM, Stefan Sedich <
> [EMAIL PROTECTED]>
> >>> > wrote:
> >>> >>
> >>> >> Thanks the idea was to have a mapper to do this, one question I had
> I
> >>> >> guess on this was would a mapper be able to talk to the say
> >>> >> CountryRepository to do the attaching of the Country on our agent
> when
> >>> >> mapping from a DTO?
> >>> >>
> >>> >>
> >>> >> Cheers
> >>> >>
> >>> >> On Sun, Oct 5, 2008 at 11:44 PM, Gustavo Ringel
> >>> >> <[EMAIL PROTECTED]> wrote:
> >>> >> > Your Update now knows how to convert to a DTO and how to validate
> >>> >> > and
> >>> >> > update...i think this is a lot of responsibilities for a single
> >>> >> > method...
> >>> >> >
> >>> >> > I like more having a Translation/Convertion Class which knows both
> >>> >> > ways...this helps you doing thinks like list.ConvertAll<AgendtDTO>
> >>> >> > ...
> >>> >> > and
> >>> >> > inverse...
> >>> >> >
> >>> >> > Gustavo.
> >>> >> >
> >>> >> > On Sun, Oct 5, 2008 at 3:38 PM, codemonkey <
> [EMAIL PROTECTED]>
> >>> >> > wrote:
> >>> >> >>
> >>> >> >> Hello,
> >>> >> >>
> >>> >> >> Just some tips really my current Service update method accepts my
> >>> >> >> updateDTO object, uses the repository to do a select of the
> object
> >>> >> >> by
> >>> >> >> ID, maps across the properties and then does an update. Is this a
> >>> >> >> good
> >>> >> >> way to do this? or could I be looking at a better way? It works
> >>> >> >> fine I
> >>> >> >> am just looking for some constructive criticism.
> >>> >> >>
> >>> >> >> public void Update(AgentUpdateDTO agentUpdateDTO) {
> >>> >> >>
> >>> >> >>            // Select from the repository by id.
> >>> >> >>            var agent =
> >>> >> >> this.agentRepository.SelectById(agentUpdateDTO.Id);
> >>> >> >>
> >>> >> >>            // Map across properties from DTO.
> >>> >> >>            agent.Code = agentUpdateDTO.Code;
> >>> >> >>            agent.Commission = agentUpdateDTO.Commission;
> >>> >> >>            agent.CompanyName = agentUpdateDTO.CompanyName;
> >>> >> >>            agent.Enabled = agentUpdateDTO.Enabled;
> >>> >> >>            agent.FirstName = agentUpdateDTO.FirstName;
> >>> >> >>            agent.Gender = agentUpdateDTO.Gender;
> >>> >> >>            agent.Password = agentUpdateDTO.Password;
> >>> >> >>            agent.Surname = agentUpdateDTO.Surname;
> >>> >> >>            agent.UserName = agentUpdateDTO.UserName;
> >>> >> >>            agent.RowVersion = agentUpdateDTO.RowVersion;
> >>> >> >>
> >>> >> >>            if (!string.IsNullOrEmpty(agentUpdateDTO.CountryCode))
> >>> >> >>                agent.Country =
> >>> >> >>
> >>> >> >>
> this.countryService.SelectByCountryCode(agentUpdateDTO.CountryCode);
> >>> >> >>
> >>> >> >>            // Validate the model and use repository to update.
> >>> >> >>            agent.Validate();
> >>> >> >>            this.agentRepository.Update(agent);
> >>> >> >>
> >>> >> >>        }
> >>> >> >>
> >>> >> >> Cheers
> >>> >> >>
> >>> >> >>
> >>> >> >>
> >>> >> >>
> >>> >> >
> >>> >> >
> >>> >> > >
> >>> >> >
> >>> >>
> >>> >>
> >>> >>
> >>> >> --
> >>> >> Stefan Sedich
> >>> >> Developer
> >>> >> Microsoft Certified Professional (MCP)
> >>> >>
> >>> >>
> >>> >
> >>> >
> >>> > >
> >>> >
> >>>
> >>>
> >>>
> >>> --
> >>> Stefan Sedich
> >>> Developer
> >>> Microsoft Certified Professional (MCP)
> >>>
> >>>
> >>
> >>
> >>
> >>
> >>
> >
> >
> > >
> >
>
>
>
> --
> Stefan Sedich
> Developer
> Microsoft Certified Professional (MCP)
>
> >
>


-- 
Ben Hart
http://blog.benhartonline.com/

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to