Automapper with nested child containers

Skip to first unread message

grumpy

unread,
Nov 11, 2011, 9:56:32 PM11/11/11
to AutoMapper-users
According to author's post in version 2.0

http://lostechies.com/jimmybogard/2011/09/29/automapper-2-0-nestedchild-containers/

but this test doesnt work, can someone point out whats wrong here ?

public class Source
{
public int SomeValue { get; set; }
}

public class Destination
{
public Destination() { }

public Destination(bool value)
{
this.WasCustom = true;
}
public bool WasCustom { get; private set; }
public int SomeValue { get; set; }
}


[TestMethod]
public void can_make_servicelocator_work()
{
Mapper.CreateMap<Source, Destination>();
var source = new Source { SomeValue = 100 };
var dest = Mapper.Map<Source, Destination>(source,
(option) => option.ConstructServicesUsing((t) => new
Destination(true)));
Assert.IsTrue(dest.WasCustom);
}

Jimmy Bogard

unread,
Nov 12, 2011, 12:49:34 PM11/12/11
to automapp...@googlegroups.com
Are you trying to make the container instantiate destination objects?


--
You received this message because you are subscribed to the Google Groups "AutoMapper-users" group.
To post to this group, send email to automapp...@googlegroups.com.
To unsubscribe from this group, send email to automapper-use...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/automapper-users?hl=en.


grumpy

unread,
Nov 14, 2011, 9:54:47 AM11/14/11
to AutoMapper-users
I am trying to take control over creation of objects since i need to
create them using EF's dataContext and then do some custom logic on
them ( setting the row version)

I cloned the latest code, and it seems like the release on nuget is
missing ConstructUsingServiceLocator method on IMappingExpression
interface, this method is checked before mapping engine uses the
delegate supplied in the Map method.



On Nov 12, 11:49 am, Jimmy Bogard <jimmy.bog...@gmail.com> wrote:
> Are you trying to make the container instantiate destination objects?
>
>
>
> On Fri, Nov 11, 2011 at 8:56 PM, grumpy <ap.sha...@gmail.com> wrote:
> > According to author's post in version 2.0
>
> >http://lostechies.com/jimmybogard/2011/09/29/automapper-2-0-nestedchi...
>
> > but this test doesnt work, can someone point out whats wrong here ?
>
> >    public class Source
> >    {
> >        public int SomeValue { get; set; }
> >    }
>
> >    public class Destination
> >    {
> >        public Destination() { }
>
> >        public Destination(bool value)
> >        {
> >            this.WasCustom = true;
> >        }
> >        public bool WasCustom { get; private set; }
> >        public int SomeValue { get; set; }
> >    }
>
> >    [TestMethod]
> >    public void can_make_servicelocator_work()
> >    {
> >        Mapper.CreateMap<Source, Destination>();
> >        var source = new Source { SomeValue = 100 };
> >        var dest = Mapper.Map<Source, Destination>(source,
> >            (option) => option.ConstructServicesUsing((t) => new
> > Destination(true)));
> >        Assert.IsTrue(dest.WasCustom);
> >    }
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "AutoMapper-users" group.
> > To post to this group, send email to automapp...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > automapper-use...@googlegroups.com.
> > For more options, visit this group at
> >http://groups.google.com/group/automapper-users?hl=en.- Hide quoted text -
>
> - Show quoted text -

grumpy

unread,
Nov 16, 2011, 12:21:32 PM11/16/11
to AutoMapper-users
anyone else facing the same issue ?
> > >http://groups.google.com/group/automapper-users?hl=en.-Hide quoted text -
>
> > - Show quoted text -- Hide quoted text -

Jimmy Bogard

unread,
Nov 16, 2011, 12:30:28 PM11/16/11
to automapp...@googlegroups.com
Yeah, that's right, I made a recent change to allow for destination types to be constructed using the container. In our case it was so that Caliburn could create view models from the container, instead of just instantiating them.

I'm planning on a 2.1 release to have this more complete support for containers (including a bug where customer type converters weren't going through the container).

Thanks,

Jimmy

Ashish Sharma

unread,
Nov 16, 2011, 5:54:08 PM11/16/11
to automapp...@googlegroups.com
Hey thanks Jimmy,
i would look out for that release...
 
i would also like to add another feature request that you change (or overload) the signature of the func in the constructor to be able to get the source object also ..
 
so that if someone needs to make some more informed decision like knowing some value of the object they can do that.
 
I modified the source but dont know how to submit a patch for approval ....
--
Regards
-ashish

Jimmy Bogard

unread,
Nov 16, 2011, 7:53:21 PM11/16/11
to automapp...@googlegroups.com
Sure, check out these pages on submitting pull requests:


Do you have a GitHub account? If so, have you already forked the code on GitHub?

Thanks,

Jimmy

Alexander Zeitler

unread,
Jun 21, 2013, 10:10:44 AM6/21/13
to automapp...@googlegroups.com
Hi,

I tried this using 2.2.1 and the tests still fail.
Should this be fixed or am I doing it wrong using the tests from this thread?

Alex

Jimmy Bogard

unread,
Jun 21, 2013, 10:52:37 AM6/21/13
to automapper-users
Which tests?


To unsubscribe from this group and stop receiving emails from it, send an email to automapper-use...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages