[Mapping by code] In ModelMapper.AddMapping, evaluate to replace Activator.CreateInstance with a compiled lambda to increase performance.
In one app, I have 360 mapped types. NH configuration was created as show under:
var map = new ModelMapper();
map.AddMappings(types);
var hbm = map.CompileMappingForAllExplicitlyAddedEntities();
hbm.autoimport = false;
configuration.AddMapping(hbm);
The time to execute the map.AddMappings (types) statement; is approximately 1268 ms and is related to running Activator.CreateInstance 360 times. Maybe by converting Activator.CreateInstance to compiled lambda we can get better performance?
is related to running Activator.CreateInstance 360 times. Maybe by converting Activator.CreateInstance to compiled lambda we can get better performance?
I don't think it would improve anything as such lambdas are not reusable - 360 lambdas would need to be compiled for each type.
If you can provide your own instances of the mapping classes, you can call the AddMapping which takes an IConformistHoldersProvider instance.
Hi @gliljas thanks for the suggestion: can you tell me some documentation about it? I couldn't find any.
@gliljas suggestion implies explicit by hand population of mappings somewhere in your code. Something like:
map.AddMapping<YourClassMapping1>();
//or
map.AddMapping(new YourClassMapping2()); //<- That's AddMapping which takes an IConformistHoldersProvider instance. So in theory you can populate somewhere list of such instances add supply it here
// Add all other mappings explicitly...