6 Tips of Separation: Listing 2.

LoadByIdCompleted event handler.

void client_LoadByIdCompleted(object sender,
PersonService.LoadByIdCompletedEventArgs e)
{
  var callback = e.UserStateasReturnResult<IPerson>;
  if (e.Error != null)
  {
    // Pass the WCF exception to the original caller
    callback.Notify(e.Error);
  }
  else
  {
    PersonService.PersonDtoperson ReturnedByService = e.Result;
    var returnValue = new Person();
    var adapter = new PersonModelToServiceDtoAdapter();
    adapter.Adapt(personReturnedByService, returnValue);
    // Pass the populated model to the original caller
    callback.Notify(returnValue);    
  }            
}

About the Author

Benjamin Day is a consultant and trainer specializing in software best practices using Microsoft tools. Ben’s main areas of emphasis include Team Foundation Server, Scrum, software testing, and software architecture. He is a Microsoft Visual Studio ALM MVP, a certified Scrum trainer via Scrum.org, and a speaker at conferences such as TechEd and Visual Studio Live! When not developing software, Ben’s been known to go running and sea kayaking in order to balance out his love of cheese, cured meats, and champagne. He can be contacted via www.benday.com.

comments powered by Disqus

Featured

Subscribe on YouTube