ASP.NET-Core-Template icon indicating copy to clipboard operation
ASP.NET-Core-Template copied to clipboard

Register the same mappings more then one time

Open HrBozhidarov opened this issue 3 years ago • 0 comments

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);

HrBozhidarov avatar Feb 28 '22 12:02 HrBozhidarov