Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion Mapping configurations

Received: by 10.224.33.148 with SMTP id h20mr15008833qad.3.1341498701341;
        Thu, 05 Jul 2012 07:31:41 -0700 (PDT)
X-BeenThere: automapper-users@googlegroups.com
Received: by 10.229.106.74 with SMTP id w10ls10639161qco.6.gmail; Thu, 05 Jul
 2012 07:31:39 -0700 (PDT)
Received: by 10.224.215.194 with SMTP id hf2mr15014037qab.0.1341498699964;
        Thu, 05 Jul 2012 07:31:39 -0700 (PDT)
Received: by 10.224.215.194 with SMTP id hf2mr15014035qab.0.1341498699939;
        Thu, 05 Jul 2012 07:31:39 -0700 (PDT)
Return-Path: <ramon.sm...@gmail.com>
Received: from mail-qa0-f46.google.com (mail-qa0-f46.google.com [209.85.216.46])
        by gmr-mx.google.com with ESMTPS id g28si952072qcq.2.2012.07.05.07.31.39
        (version=TLSv1/SSLv3 cipher=OTHER);
        Thu, 05 Jul 2012 07:31:39 -0700 (PDT)
Received-SPF: pass (google.com: domain of ramon.sm...@gmail.com designates 209.85.216.46 as permitted sender) client-ip=209.85.216.46;
Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of ramon.sm...@gmail.com designates 209.85.216.46 as permitted sender) smtp.mail=ramon.sm...@gmail.com; dkim=pass header...@gmail.com
Received: by qadb17 with SMTP id b17so3852323qad.19
        for <automapper-users@googlegroups.com>; Thu, 05 Jul 2012 07:31:39 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20120113;
        h=mime-version:date:message-id:subject:from:to:content-type;
        bh=tQoyvuACgDi8YW9PYBA3Q254fpnHEQodkfIGVALPprI=;
        b=qgqmGNMhoE0YU7ELx/QMwBm9s5I70d6NG/v0V2fCrOD8t6rBC6pu63NkIiNXPxkwJ3
         lSqrXO5ANPC/BWuSXFwN7Y3HrYw3jvBJ10TgZBC6Zk1Qfl4+qqQlSsqWAscjpPSDdsRR
         rDQuTQDeT7S27ptoBUVB+r7WY4i1kcH0SGJ/9Wfj/mWLqJvrP7IVy8boiNJyxA7omAqx
         CMGey/44d/rLjW/b9PpEDpBfuWdHTXM6sL8ae6krYEI4mIAO1yPPjRNpWbkiotfJ3nzx
         t9krTHf5byv9NdXUk/m+umMR+XLl2y+evYh4WR+jAeAjuNB6F82/QZ4xS1JsWN0Fbucl
         g9GA==
MIME-Version: 1.0
Received: by 10.42.39.17 with SMTP id f17mr13537302ice.3.1341498699694; Thu,
 05 Jul 2012 07:31:39 -0700 (PDT)
Received: by 10.43.125.10 with HTTP; Thu, 5 Jul 2012 07:31:39 -0700 (PDT)
Date: Thu, 5 Jul 2012 16:31:39 +0200
Message-ID: <CAM6HnAJ_xsrf3zQ=kGem3a+MTPWNeU2S1mkag65NLmWQaCC...@mail.gmail.com>
Subject: Mapping configurations
From: Ramon Smits <ramon.sm...@gmail.com>
To: automapper-users@googlegroups.com
Content-Type: multipart/alternative; boundary=90e6ba614a6e76434904c416012c

--90e6ba614a6e76434904c416012c
Content-Type: text/plain; charset=ISO-8859-1

I usually try to separate the mapping code from the code that needs the
mapping. Usually I try injecting a mapping via a Func<SourceType,
DestinationType> or Action<SourceType, DestinationType> when mappings are
shared and otherwise I put the mapping config initialization in a static
constructor so that it is only run once. This makes testing more easy as I
can now test the mapping separate from the code that needs the mapping.

Furthermore, it would be nice if in a future version of automapper it would
be possible to define mappings via seperate classes. For example something
like:


	public class FromTypeAToBMapping : TypeMap<A, B>
	{
		public FromTypeAToBMapping()
		{
			ForMember(d => d.ID, o => o.Ignore());
			ForMember(d => d.BusinessNumber, o => o.MapFrom(s => s.BusinessCode));
		}
	}

	ConfigurationProvider.ImportMap(new FromTypeAToBMapping());
	ConfigurationProvider.AssertConfigurationIsValid();


I don't know if such logic is already requested of in progress but I would
like this very much!

How do others use automapper with large sets of mappings?
-- 
Ramon

--90e6ba614a6e76434904c416012c
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

<div><br></div>I usually try to=A0separate=A0the mapping code from the code=
 that needs the mapping. Usually I try injecting a mapping via a Func&lt;So=
urceType, DestinationType&gt; or Action&lt;SourceType, DestinationType&gt; =
when mappings are shared and otherwise I put the mapping config=A0initializ=
ation=A0in a static constructor so that it is only run once. This makes tes=
ting more easy as I can now test the mapping=A0separate=A0from the code tha=
t needs the mapping.<div>
<br></div><div>Furthermore, it would be nice if in a future version of auto=
mapper it would be possible to define mappings via seperate classes. For ex=
ample something like:</div><div><br></div><div><br></div><div><pre style=3D=
"font-family:DejaVu Sans Mono;font-size:15;color:#b9bdb6;background:#1b2426=
">
	<span style=3D"background:#2f2d1d">public</span>=A0<span style=3D"backgrou=
nd:#2f2d1d">class</span>=A0<span style=3D"color:#5ba1cf">FromTypeAToBMappin=
g</span>=A0:=A0<span style=3D"color:#f0f0f0">TypeMap</span>&lt;<span style=
=3D"color:#f0f0f0">A</span>,=A0<span style=3D"color:#f0f0f0">B</span>&gt;
	{
		<span style=3D"background:#2f2d1d">public</span>=A0<span style=3D"color:#=
f0f0f0">FromTypeAToBMapping</span>()
		{
			<span style=3D"color:#f0f0f0">ForMember</span>(<span style=3D"color:#f0f=
0f0">d</span>=A0=3D&gt;=A0<span style=3D"color:#f0f0f0">d</span>.<span styl=
e=3D"color:#f0f0f0">ID</span>,=A0<span style=3D"color:#f0f0f0">o</span>=A0=
=3D&gt;=A0<span style=3D"color:#f0f0f0">o</span>.<span style=3D"color:#f0f0=
f0">Ignore</span>());
			<span style=3D"color:#f0f0f0">ForMember</span>(<span style=3D"color:#f0f=
0f0">d</span>=A0=3D&gt;=A0<span style=3D"color:#f0f0f0">d</span>.<span styl=
e=3D"color:#f0f0f0">BusinessNumber</span>,=A0<span style=3D"color:#f0f0f0">=
o</span>=A0=3D&gt;=A0<span style=3D"color:#f0f0f0">o</span>.<span style=3D"=
color:#f0f0f0">MapFrom</span>(<span style=3D"color:#f0f0f0">s</span>=A0=3D&=
gt;=A0<span style=3D"color:#f0f0f0">s</span>.<span style=3D"color:#f0f0f0">=
BusinessCode</span>));
		}
	}
=20
	<span style=3D"color:#f0f0f0">ConfigurationProvider</span>.<span style=3D"=
color:#f0f0f0">ImportMap</span>(<span style=3D"background:#2f2d1d">new</spa=
n>=A0<span style=3D"color:#f0f0f0">FromTypeAToBMapping</span>());
	<span style=3D"color:#f0f0f0">ConfigurationProvider</span>.<span style=3D"=
color:#f0f0f0">AssertConfigurationIsValid</span>();
</pre></div><div><br></div><div>I don&#39;t know if such logic is already r=
equested of in progress but I would like this very much!</div><div><div><di=
v><div><br></div><div>How do others use automapper with large sets of mappi=
ngs?</div>
-- <br><div>Ramon</div><br>
</div></div></div>

--90e6ba614a6e76434904c416012c--