First post here, so first things first: Thanks for AutoMapper,
absolutely nice to work with.
I have a scenario where I want to have multiple mapping containers
within the same AppDomain. A small part of the system has its own
mapping scenarios which I don't want to expose to the full
application. I have browsed through the API and I am getting the
feeling that this is not possible.
Something like: var mapper = Mapper.CreateScopedMapper();
mapper.CreateMap<>() ....
mapper.Map<>() ....
I think you can do that by creating multiple instances of the MappingEngine class. I havnt tried it and dont know how much more complexity is involved, but I think I read somewhere that that is the solution to these kind of scenarios.
On Wed, Feb 22, 2012 at 2:57 AM, Dennis <dennis.s...@gmail.com> wrote: > Hi!
> First post here, so first things first: Thanks for AutoMapper, > absolutely nice to work with.
> I have a scenario where I want to have multiple mapping containers > within the same AppDomain. A small part of the system has its own > mapping scenarios which I don't want to expose to the full > application. I have browsed through the API and I am getting the > feeling that this is not possible.
> -- > You received this message because you are subscribed to the Google Groups > "AutoMapper-users" group. > To post to this group, send email to automapper-users@googlegroups.com. > To unsubscribe from this group, send email to > automapper-users+unsubscribe@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/automapper-users?hl=en.
You can have multiple instances of the IMappingEngine. This enable you to have multple mapping configurations within one app domain.
Don't know why you need seperate configurations. Do you have conflicting mappings? If not then you might as well just pass an IMappingEngine reference around. (AutoMapper.Mapper.Engine) which is probably a good thing anyway when you use dependancy injection. Just google on AutoMapper IMappingEngine and you will get several posts. This makes the design much more explicit as you have the mapping engine (IMappingEngine) and its configuration (IConfiguration) where the configuration should be only done once in an app domain.
On Wed, Feb 22, 2012 at 2:57 AM, Dennis <dennis.s...@gmail.com> wrote: > Hi!
> First post here, so first things first: Thanks for AutoMapper, > absolutely nice to work with.
> I have a scenario where I want to have multiple mapping containers > within the same AppDomain. A small part of the system has its own > mapping scenarios which I don't want to expose to the full > application. I have browsed through the API and I am getting the > feeling that this is not possible.
> -- > You received this message because you are subscribed to the Google Groups > "AutoMapper-users" group. > To post to this group, send email to automapper-users@googlegroups.com. > To unsubscribe from this group, send email to > automapper-users+unsubscribe@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/automapper-users?hl=en.
Here you see that the static Mapper class is just a wrapper then Lazy creates the configuration and engine instances. If you want to create your own instances then you can do so as you see in the above code reference.
In my version I can do it like
var config = new AutoMapper.Configuration((AutoMapper.ITypeMapFactory)new AutoMapper.TypeMapFactory(), AutoMapper.Mappers.MapperRegistry.AllMappers()); var engine = new AutoMapper.MappingEngine(config);
On Wed, Feb 22, 2012 at 2:57 AM, Dennis <dennis.s...@gmail.com> wrote: > Hi!
> First post here, so first things first: Thanks for AutoMapper, > absolutely nice to work with.
> I have a scenario where I want to have multiple mapping containers > within the same AppDomain. A small part of the system has its own > mapping scenarios which I don't want to expose to the full > application. I have browsed through the API and I am getting the > feeling that this is not possible.
> -- > You received this message because you are subscribed to the Google Groups > "AutoMapper-users" group. > To post to this group, send email to automapper-users@googlegroups.com. > To unsubscribe from this group, send email to > automapper-users+unsubscribe@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/automapper-users?hl=en.
On Tue, Feb 21, 2012 at 7:57 PM, Dennis <dennis.s...@gmail.com> wrote: > Hi!
> First post here, so first things first: Thanks for AutoMapper, > absolutely nice to work with.
> I have a scenario where I want to have multiple mapping containers > within the same AppDomain. A small part of the system has its own > mapping scenarios which I don't want to expose to the full > application. I have browsed through the API and I am getting the > feeling that this is not possible.
> You can also look at AutoMapperAssist, very nice little wrapper around > AutoMapper, which helps isolate the creation of isolated mapper > classes: https://github.com/darrencauthon/AutoMapperAssist
> There's Nuget package as well.
What does this do? I just browsed the code and it seems like a wrapper around AutoMapper which to me sounds a bit unneeded. The project doesn't explain why it does that and what problem it tries to fix.
On Wed, Feb 22, 2012 at 7:37 AM, Ramon Smits <ramon.sm...@gmail.com> wrote:
>> You can also look at AutoMapperAssist, very nice little wrapper around >> AutoMapper, which helps isolate the creation of isolated mapper >> classes: https://github.com/darrencauthon/AutoMapperAssist
>> There's Nuget package as well.
> What does this do? I just browsed the code and it seems like a wrapper > around AutoMapper which to me sounds a bit unneeded. The project doesn't > explain why it does that and what problem it tries to fix.
It actually uses its own IMappingEngine for each instance, which solves the problem you described.
Look at the ctor of Mapper class, it creates new instance of MappingEngine, and uses it. It's very simple to use, just inherit from Mapper<TSource, TDest> and override DefineMap:
public class POSCurrencyDetailDTOToCurrencyMapper : Mapper<POSCurrencyDetailDTO, POSCurrency> { public override void DefineMap(IConfiguration configuration) { base.DefineMap(configuration); configuration.CreateMap<POSCurrencyDetailDTO, POSCurrency>() .ForMember(d => d.Code, opt => opt.MapFrom(s => s.CurrencyCode)); } }
That will isolate your mapping to only this class, and then you can use it like this:
var myMapper = new POSCurrencyDetailDTOToCurrencyMapper(); var mapped = myMapper.CreateInstance(myDTO);
Added benefit is that Mapper<TSoirce, TDest> implements IAbstractMapper<TSource, TDest>, so you can use actually the interface to inject mappers in your code for unit testing, etc.
Cheers -- Svetoslav Milenov (Sunny)
Artificial Intelligence is no match for natural stupidity.
> It actually uses its own IMappingEngine for each instance, which > solves the problem you described.
Yes, but why :-) I don't understand why you would want to do that. It also makes any automatic mappings like collections impossible and if you do that why not just depend on the interfaces that AutoMapper provides instead of relying on an additional set of interfaces?
Added benefit is that Mapper<TSoirce, TDest> implements
> IAbstractMapper<TSource, TDest>, so you can use actually the interface > to inject mappers in your code for unit testing, etc.
And why would I just do that with the AutoMapper interfaces?
I had seen the code after sending my initial message to the list (and I should have checked it before sending mails to the list), thanks for confirming that this is indeed the -way-to-go- ! ;-).
Thanks,
Dennis
From: automapper-users@googlegroups.com [mailto:automapper-users@googlegroups.com] On Behalf Of Ramon Smits Sent: woensdag 22 februari 2012 10:01 To: automapper-users@googlegroups.com Subject: Re: Private AutoMapping container.
Here you see that the static Mapper class is just a wrapper then Lazy creates the configuration and engine instances. If you want to create your own instances then you can do so as you see in the above code reference.
In my version I can do it like
var config = new AutoMapper.Configuration((AutoMapper.ITypeMapFactory)new AutoMapper.TypeMapFactory(), AutoMapper.Mappers.MapperRegistry.AllMappers());
var engine = new AutoMapper.MappingEngine(config);
Hope this helps.
On Wed, Feb 22, 2012 at 2:57 AM, Dennis <dennis.s...@gmail.com> wrote:
Hi!
First post here, so first things first: Thanks for AutoMapper, absolutely nice to work with.
I have a scenario where I want to have multiple mapping containers within the same AppDomain. A small part of the system has its own mapping scenarios which I don't want to expose to the full application. I have browsed through the API and I am getting the feeling that this is not possible.
Something like: var mapper = Mapper.CreateScopedMapper(); mapper.CreateMap<>() .... mapper.Map<>() ....
Is this possible? Or is it planned?
Thanks in advance for your answer!
Finest regards, Dennis
-- You received this message because you are subscribed to the Google Groups "AutoMapper-users" group. To post to this group, send email to automapper-users@googlegroups.com. To unsubscribe from this group, send email to automapper-users+unsubscribe@googlegroups.com <mailto:automapper-users%2Bunsubscribe@googlegroups.com> . For more options, visit this group at http://groups.google.com/group/automapper-users?hl=en.
--
Ramon
-- You received this message because you are subscribed to the Google Groups "AutoMapper-users" group. To post to this group, send email to automapper-users@googlegroups.com. To unsubscribe from this group, send email to automapper-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/automapper-users?hl=en.
Thanks! The reason why I need this configuration is because I don't want the conversion ability to leak out of the area where I explicitly need it since this is rather isolated from the other parts of the system, so it might not always be clear
a conversion was setup in the first place.
Cheers,
Dennis
From: automapper-users@googlegroups.com [mailto:automapper-users@googlegroups.com] On Behalf Of Ramon Smits Sent: woensdag 22 februari 2012 9:33 To: automapper-users@googlegroups.com Subject: Re: Private AutoMapping container.
You can have multiple instances of the IMappingEngine. This enable you to have multple mapping configurations within one app domain.
Don't know why you need seperate configurations. Do you have conflicting mappings? If not then you might as well just pass an IMappingEngine reference around. (AutoMapper.Mapper.Engine) which is probably a good thing anyway when you use dependancy injection. Just google on AutoMapper IMappingEngine and you will get several posts. This makes the design much more explicit as you have the mapping engine (IMappingEngine) and its configuration (IConfiguration) where the configuration should be only done once in an app domain.
On Wed, Feb 22, 2012 at 2:57 AM, Dennis <dennis.s...@gmail.com> wrote:
Hi!
First post here, so first things first: Thanks for AutoMapper, absolutely nice to work with.
I have a scenario where I want to have multiple mapping containers within the same AppDomain. A small part of the system has its own mapping scenarios which I don't want to expose to the full application. I have browsed through the API and I am getting the feeling that this is not possible.
Something like: var mapper = Mapper.CreateScopedMapper(); mapper.CreateMap<>() .... mapper.Map<>() ....
Is this possible? Or is it planned?
Thanks in advance for your answer!
Finest regards, Dennis
-- You received this message because you are subscribed to the Google Groups "AutoMapper-users" group. To post to this group, send email to automapper-users@googlegroups.com. To unsubscribe from this group, send email to automapper-users+unsubscribe@googlegroups.com <mailto:automapper-users%2Bunsubscribe@googlegroups.com> . For more options, visit this group at http://groups.google.com/group/automapper-users?hl=en.
--
Ramon
-- You received this message because you are subscribed to the Google Groups "AutoMapper-users" group. To post to this group, send email to automapper-users@googlegroups.com. To unsubscribe from this group, send email to automapper-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/automapper-users?hl=en.
Someone had an itch, and scratched it. What more reason do we need? ;-).
From: automapper-users@googlegroups.com [mailto:automapper-users@googlegroups.com] On Behalf Of Ramon Smits Sent: woensdag 22 februari 2012 14:38 To: automapper-users@googlegroups.com Subject: Re: Private AutoMapping container.
What does this do? I just browsed the code and it seems like a wrapper around AutoMapper which to me sounds a bit unneeded. The project doesn't explain why it does that and what problem it tries to fix.
-- You received this message because you are subscribed to the Google Groups "AutoMapper-users" group. To post to this group, send email to automapper-users@googlegroups.com. To unsubscribe from this group, send email to automapper-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/automapper-users?hl=en.
On Wed, Feb 22, 2012 at 8:21 AM, Ramon Smits <ramon.sm...@gmail.com> wrote: >> It actually uses its own IMappingEngine for each instance, which >> solves the problem you described.
> Yes, but why :-) I don't understand why you would want to do that. It also > makes any automatic mappings like collections impossible and if you do that > why not just depend on the interfaces that AutoMapper provides instead of > relying on an additional set of interfaces?
Its just a convenient wrapper (at least for me). It has all 3 most used methods CreateInstance, LoadIntoInstance and CreateSet. Keeps things separated.
>> Added benefit is that Mapper<TSoirce, TDest> implements >> IAbstractMapper<TSource, TDest>, so you can use actually the interface >> to inject mappers in your code for unit testing, etc.
> And why would I just do that with the AutoMapper interfaces?
You can, and you'll most probably end up doing something very similar. Of course, your implementation will fit better your needs, and could be better. Its up to you.
At the end, as someone else pointed out - someone had an itch, and scratched it. I found it useful, and I use it when I need it.
Cheers
-- Svetoslav Milenov (Sunny)
Artificial Intelligence is no match for natural stupidity.
You can always create instances of the ConfigurationStore and MappingEngine as needed. It's not as easy as I would like, which is why folks create wrappers. It's my intention to build AutoMapper 3.0 as a completely instance-based model-first, and static as just the wrapper.
On Tue, Feb 21, 2012 at 7:57 PM, Dennis <dennis.s...@gmail.com> wrote: > Hi!
> First post here, so first things first: Thanks for AutoMapper, > absolutely nice to work with.
> I have a scenario where I want to have multiple mapping containers > within the same AppDomain. A small part of the system has its own > mapping scenarios which I don't want to expose to the full > application. I have browsed through the API and I am getting the > feeling that this is not possible.
> -- > You received this message because you are subscribed to the Google Groups > "AutoMapper-users" group. > To post to this group, send email to automapper-users@googlegroups.com. > To unsubscribe from this group, send email to > automapper-users+unsubscribe@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/automapper-users?hl=en.
On Thu, Feb 23, 2012 at 8:23 AM, Jimmy Bogard <jimmy.bog...@gmail.com> wrote: > You can always create instances of the ConfigurationStore and MappingEngine > as needed. It's not as easy as I would like, which is why folks create > wrappers. It's my intention to build AutoMapper 3.0 as a completely > instance-based model-first, and static as just the wrapper.
Good news :)
Thanks
-- Svetoslav Milenov (Sunny)
Artificial Intelligence is no match for natural stupidity.
Cool! Have you branched out to a 3.0 devel tree already?
From: automapper-users@googlegroups.com [mailto:automapper-users@googlegroups.com] On Behalf Of Jimmy Bogard Sent: donderdag 23 februari 2012 15:23 To: automapper-users@googlegroups.com Subject: Re: Private AutoMapping container.
You can always create instances of the ConfigurationStore and MappingEngine as needed. It's not as easy as I would like, which is why folks create wrappers. It's my intention to build AutoMapper 3.0 as a completely instance-based model-first, and static as just the wrapper.
On Tue, Feb 21, 2012 at 7:57 PM, Dennis <dennis.s...@gmail.com> wrote:
Hi!
First post here, so first things first: Thanks for AutoMapper, absolutely nice to work with.
I have a scenario where I want to have multiple mapping containers within the same AppDomain. A small part of the system has its own mapping scenarios which I don't want to expose to the full application. I have browsed through the API and I am getting the feeling that this is not possible.
Something like: var mapper = Mapper.CreateScopedMapper(); mapper.CreateMap<>() .... mapper.Map<>() ....
Is this possible? Or is it planned?
Thanks in advance for your answer!
Finest regards, Dennis
-- You received this message because you are subscribed to the Google Groups "AutoMapper-users" group. To post to this group, send email to automapper-users@googlegroups.com. To unsubscribe from this group, send email to automapper-users+unsubscribe@googlegroups.com <mailto:automapper-users%2Bunsubscribe@googlegroups.com> . For more options, visit this group at http://groups.google.com/group/automapper-users?hl=en.
-- You received this message because you are subscribed to the Google Groups "AutoMapper-users" group. To post to this group, send email to automapper-users@googlegroups.com. To unsubscribe from this group, send email to automapper-users+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/automapper-users?hl=en.
> You can always create instances of the ConfigurationStore and > MappingEngine as needed. It's not as easy as I would like, which is why > folks create wrappers. It's my intention to build AutoMapper 3.0 as a > completely instance-based model-first, and static as just the wrapper.****
> On Tue, Feb 21, 2012 at 7:57 PM, Dennis <dennis.s...@gmail.com> wrote:****
> Hi!
> First post here, so first things first: Thanks for AutoMapper, > absolutely nice to work with.
> I have a scenario where I want to have multiple mapping containers > within the same AppDomain. A small part of the system has its own > mapping scenarios which I don't want to expose to the full > application. I have browsed through the API and I am getting the > feeling that this is not possible.
> -- > You received this message because you are subscribed to the Google Groups > "AutoMapper-users" group. > To post to this group, send email to automapper-users@googlegroups.com. > To unsubscribe from this group, send email to > automapper-users+unsubscribe@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/automapper-users?hl=en.****
> ** **
> -- > You received this message because you are subscribed to the Google Groups > "AutoMapper-users" group. > To post to this group, send email to automapper-users@googlegroups.com. > To unsubscribe from this group, send email to > automapper-users+unsubscribe@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/automapper-users?hl=en.****
> -- > You received this message because you are subscribed to the Google Groups > "AutoMapper-users" group. > To post to this group, send email to automapper-users@googlegroups.com. > To unsubscribe from this group, send email to > automapper-users+unsubscribe@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/automapper-users?hl=en.