/// <summary> /// Called just before changes are saved to the database. /// </summary> /// <param name="entityDbContext">The database context.</param> public void PreSaveChanges(EntityDbContext entityDbContext) { _options = entityDbContext.EntityContextOptions.GetExtension <EntityCacheOptions>(); var entityTypes = _options.CachedTypesByCachedEntity .Values .Select(a => a.EntityType) .ToList(); _modifiedEntities = entityDbContext.ChangeTracker .Entries() .Where(a => a.Entity is IEntity && entityTypes.Contains(a.Entity.GetType())) .Where(a => a.State == EntityState.Added || a.State == EntityState.Modified || a.State == EntityState.Deleted) .ToDictionary(a => ( IEntity )a.Entity, a => a.State); }
public static IServiceCollection AddEntityCache(this IServiceCollection services, Action <EntityCacheOptions> cacheOptions) { services.Configure(cacheOptions); var options = new EntityCacheOptions(); cacheOptions(options); if (options.Get != null && options.Set != null && options.Del != null) { services.TryAdd(ServiceDescriptor.Transient(typeof(IEntityStorage <,>), typeof(OutEntityStorage <,>))); } CacheHelper.Options = options; services.TryAdd(ServiceDescriptor.Transient(typeof(IEntityStorage <,>), typeof(MemoryEntityStorage <,>))); services.TryAdd(ServiceDescriptor.Transient(typeof(IEntityCache <,>), typeof(EntityCache <,>))); services.TryAdd(ServiceDescriptor.Transient(typeof(IEntityCache <, ,>), typeof(EntityCache <, ,>))); return(services); }
/// <summary> /// Creates a new instance of the <see cref="EntityCacheOptionsBuilder"/> class. /// </summary> /// <param name="options">The options to be built.</param> internal EntityCacheOptionsBuilder(EntityCacheOptions options) { _options = options; }