/// <summary> /// Enables use of entity types for this entity database context. /// </summary> /// <param name="entityOptionsBuilder">The entity options builder.</param> /// <param name="optionsAction">The action to call for configuring cache options.</param> /// <returns>The options builder so that further configuration can be chained.</returns> public static EntityDbContextOptionsBuilder UseEntityTypes( this EntityDbContextOptionsBuilder entityOptionsBuilder, Action <EntityTypesOptionsBuilder> optionsAction = null) { // // Ensure the cache system has been initialized and register our // cached types. // entityOptionsBuilder.UseEntityCache(a => { a.WithCachedType <EntityType, CachedEntityType>(); }); // // Register our custom options. // var options = entityOptionsBuilder.FindExtension <EntityTypesOptions>() ?? new EntityTypesOptions(); entityOptionsBuilder.AddOrReplaceExtension(options); // // Register ourselves and any entities we have. // entityOptionsBuilder.WithPlugin <EntityTypesPlugin>(); entityOptionsBuilder.WithEntity <EntityType, DataSet <EntityType> >(); // // Allow the caller to customize our options. // var optionsBuilder = new EntityTypesOptionsBuilder(options); optionsAction?.Invoke(optionsBuilder); return(entityOptionsBuilder); }
/// <summary> /// Enables use of caching for this entity database context. /// </summary> /// <param name="entityOptionsBuilder">The entity options builder.</param> /// <param name="optionsAction">The action to call for configuring cache options.</param> /// <returns>The options builder so that further configuration can be chained.</returns> public static EntityDbContextOptionsBuilder UseEntityCache( this EntityDbContextOptionsBuilder entityOptionsBuilder, Action <EntityCacheOptionsBuilder> optionsAction = null) { var options = entityOptionsBuilder.FindExtension <EntityCacheOptions>() ?? new EntityCacheOptions(); if (options.MemoryCache == null) { var memoryOptions = Microsoft.Extensions.Options.Options.Create(new MemoryCacheOptions()); options.MemoryCache = new MemoryCache(memoryOptions); } entityOptionsBuilder.AddOrReplaceExtension(options); entityOptionsBuilder.WithPlugin <CachePlugin>(); entityOptionsBuilder.UseSaveHook <CachedEntitySaveHook>(); var optionsBuilder = new EntityCacheOptionsBuilder(options); optionsAction?.Invoke(optionsBuilder); return(entityOptionsBuilder); }