ASP.NET-Core-Template
ASP.NET-Core-Template copied to clipboard
Register the same mappings more then one time
We register custom mappings more then one time in GetCustomMappings.
When we use from i in t.GetTypeInfo().GetInterfaces() we get all interfaces IMapFrom, IMapTo and IHaveCustomMappings => we will register 3 times our mappings if they exist in our model.
var customMaps = from t in types
from i in t.GetTypeInfo().GetInterfaces()
where typeof(IHaveCustomMappings).GetTypeInfo().IsAssignableFrom(t) &&
!t.GetTypeInfo().IsAbstract &&
!t.GetTypeInfo().IsInterface
select (IHaveCustomMappings)Activator.CreateInstance(t);
Fix
var customMaps = from t in types
where typeof(IHaveCustomMappings).GetTypeInfo().IsAssignableFrom(t) &&
!t.GetTypeInfo().IsAbstract &&
!t.GetTypeInfo().IsInterface
select (IHaveCustomMappings)Activator.CreateInstance(t);