AutoMapper/AutoMapper — Issue #176: AssertConfigurationIsValid does not fail when ResolveUsing<>() without a default constructor
Author: bcbeatty
Created: 2012-02-29 21:12:00+00:00
State: open

I have a ValueResolver without a default constructor AssertConfigurationIsValid did not throw an exception, when I did not include a ConstructedBy(() => new Resolver

ex:
//correct
CreateMap().ForMember(c => c.FinancialYearEnd, o => o.ResolveUsing().ConstructedBy(()=> new ImportantDateResolver(ImportantDateTypes.FinancialYearEnd)));
// should fail but does not
CreateMap().ForMember(c => c.FinancialYearEnd, o => o.ResolveUsing());

public class ImportantDateResolver : ValueResolver
{
private readonly ImportantDateTypes _importantDateType;

public ImportantDateResolver(ImportantDateTypes importantDateType)
{
_importantDateType = importantDateType;
}

protected override DateTime? ResolveCore(InsuredCompany source)
{
return GetImportantDate(source, _importantDateType);
}

private DateTime? GetImportantDate(Company domain, ImportantDateTypes importantDateType)
{
var d = domain.CompanyImportantDates.FirstOrDefault(item => item.ImportantDateTypeId == (int)importantDateType && item.SoftDelete == false);
if (d != null)
{
return d.DateValue;
}
return null;
}

}