Is the Profile-overwrite behavior reliable?

16 views
Skip to first unread message

cjm.ai...@gmail.com

unread,
Jun 9, 2017, 3:12:18 PM6/9/17
to AutoMapper-users
I noticed that when you do something like this:


            var config = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile<Profile1>();
                cfg.AddProfile<Profile2>();
            };


        private class Profile1 : Profile
        {
            public Profile1()
            {
                this.CreateMap<ASource, ADest>()...
            }
        }

        private class Profile2 : Profile
        {
            public Profile2()
            {
                this.CreateMap<ASource, ADest>()...
            }
        }

the CreateMap statement in Profile2 will wipe out the CreateMap statement from Profile1. In other words, the TypeMap configuration from Profile1 gets overwritten by the same TypeMap configuration from Profile2.

It seems like this happens because Profile2 was Added after Profile1. But I can't be sure without knowing the code.

Is this behavior intentional?
Is it reliable?

Thanks.

Jimmy Bogard

unread,
Jun 9, 2017, 5:39:53 PM6/9/17
to automapper-users
No. Don't do this. In future versions this will throw an exception.

--
You received this message because you are subscribed to the Google Groups "AutoMapper-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to automapper-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

cjm.ai...@gmail.com

unread,
Jun 9, 2017, 6:57:33 PM6/9/17
to AutoMapper-users
Oh, darn. I was going to use it to set up some default stuff. Nevermind.
To unsubscribe from this group and stop receiving emails from it, send an email to automapper-use...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages