Skip to content

v2.6.0

Choose a tag to compare

@MarvinKlein1508 MarvinKlein1508 released this 21 Sep 13:01
· 26 commits to master since this release

Whats new?

  • Added static field TypeAttributeCache.CacheIsInitialized which is being used to check if the TypeAttributeCache has already been initialized. This comes in handy when you'll need two different IDbController implementations within the same project. In addition it allows to manually setup the cache during application startup.

Breaking changes

The default static constructor implementation has been changed a little bit. The static constructor should now only initialize the TypeAttributeCache when this property is set to false.

You can update your static constructors to this code for example:

/// <summary>
/// Static constructor to initialize the TypeAttributeCache
/// </summary>
static MySqlController()
{
    if (!TypeAttributeCache.CacheIsInitialized)
    {
        // INIT Dapper for CompareField
        foreach (Type type in SingletonTypeAttributeCache.CacheAll<CompareFieldAttribute>((att) => att.FieldNames))
        {
            SqlMapper.SetTypeMap(type, new CustomPropertyTypeMap(
                type,
                (type, columnName) =>
                {
                    PropertyInfo? prop = SingletonTypeAttributeCache.Get(type, columnName);

                    return prop is null ? type.GetProperty(columnName, BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance) : prop;

                }
            ));
        }

        TypeAttributeCache.CacheIsInitialized = true;
    }
}