AutoMapper flattens Domain Models but does it do the opposite? If not, what does?
Asked Answered
F

3

7

I've been reading up on AutoMapper because of a response to one of my earlier questions here.

It says that AutoMapper flattens complex domain models, but I need something that does the opposite. I need to wire up my view models (flattened domain models) to the complex domain models so that I can quickly transform a view model into a domain model.

Is there anything similar to AutoMapper that takes a view model and makes it into a complex domain model?

Fearless answered 24/7, 2009 at 5:36 Comment(1)
you can do it with the ValueInjecter valueinjecter.codeplex.comRehnberg
H
2

Not really, because it would have to be extremely conventional to be useful. It's easy to discern patterns when flattening, but the other way 'round... just too much custom logic.

Henson answered 1/8, 2009 at 3:21 Comment(1)
not only that, but it seems like two-way mapping is a questionable practice: lostechies.com/jimmybogard/2009/09/18/….Duppy
P
4

You do!. You create a MapToModel method where you do the right-hand/left-hand coding and sync the two together.

public MyModel MapToModel(MyViewModelForm vmf)
{
  //new up MyModel model;
  model.foo = vmf.foo;

  return model;
}

If applications coded themselves, what exactly would we do for a living...?

Puffin answered 19/1, 2010 at 16:18 Comment(0)
H
2

Not really, because it would have to be extremely conventional to be useful. It's easy to discern patterns when flattening, but the other way 'round... just too much custom logic.

Henson answered 1/8, 2009 at 3:21 Comment(1)
not only that, but it seems like two-way mapping is a questionable practice: lostechies.com/jimmybogard/2009/09/18/….Duppy
R
2

the ValueInjecter does it, and it's quite easy to use:

//flatenning
personDto.InjectFrom<FlatValueInjection>(person);

//unflattening
person.InjectFrom<UnflatValueInjection>(personDto);

and

//this is just mapping without flattening/unflattening
foo.InjectFrom(bar)
Rehnberg answered 10/6, 2010 at 11:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.