fluentsprings / ExpressMapper

Mapping .Net types
http://www.expressmapper.org
Other
310 stars 65 forks source link

how to do something like IgnoreAllNonExisting #105

Open nsgaga opened 8 years ago

nsgaga commented 8 years ago

Hi, With AutoMapper we were able to make an extension method like that (that's a known one on the web - e.g http://stackoverflow.com/questions/954480/automapper-ignore-the-rest/6474397#6474397) which uses TypeMap or something similar to get all properties that do not match and Ignore them. How can I achieve something like that? Thanks !

anisimovyuriy commented 8 years ago

Dear @nsgaga,

Thanks for your input! Actually there is a task in. Backlog that will be released this weekend. So you will have the following syntax: .IgnoreAll

nsgaga commented 8 years ago

Yuriy, thanks very much for your response! (and the free work on this, looking interesting), I've seen that issue but seemed like a 'distant prospect', this weekend is great. (maybe you should join or kill this one).

One more (I don't want to spam you w/ new issues here:) - is 'default constructor' a must for now? I've used 'Instantiate' but still complains, I use DI/Autofac so very few empty.ctor-s. (and note, I've read through docs, most I think, may be missing something still)

anisimovyuriy commented 8 years ago

Dear @nsgaga ,

Could you post an example of .Instantiate. I wonder how do you do it? Is it something like that: .Instantiate((src, dest) => IoC.Resolve<TYourObject>()) or you have setup all you DI's and expect that destination instance will be automatically resolved by Expressmapper using your IoC / Autofac?

First case is kind of anti-pattern of IoC which is called "ServiceLocator". Second case if you want to have automatic resolution there has to be injection into Expressmapper - how to create / resolve destination objects. I'm going to create a task regarding second case.

Thanks, Yuriy

nsgaga commented 8 years ago

Hi Yuriy, you can disregard that (.Instantiate not working) - I didn't have the time to properly debug it, I just ran an isolated test and .Instantiate does work fine, and no exception is thrown. Problem was in my code that didn't run the register (I'm configuring per modules, profiles for each library, plugin sort of) and given I couldn't run it fully w/o IgnoreAll I've drawn wrong conclusions :). Sorry about that. I am using IoC - but this is during configuration stage, when I have a 'container' available so it's ok I think (vs anti-pattern). Also with Autofac you can DI the 'scope', which is kind of 'cheating' :). In my case I actually don't really create anything (I could just return 'null' from .Instantiate), I'm using the overload which takes both source and destination (already created) and that was also throwing (even though no object was needed).

nickcoad commented 8 years ago

@nsgaga I have written an extension method called IgnoreAll() that you can use to auto-ignore all properties so that you then only need to add the ones you want. See here: https://github.com/fluentsprings/ExpressMapper/issues/92#issuecomment-250356209