Beispiel #1
0
        /// <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>
        /// Configures the entity database to use the Sqlite provider.
        /// </summary>
        /// <param name="optionsBuilder"></param>
        /// <returns></returns>
        public static EntityDbContextOptionsBuilder UseSqlite(this EntityDbContextOptionsBuilder optionsBuilder)
        {
            //optionsBuilder.BaseOptionsBuilder.ReplaceService<IMigrationsSqlGenerator, SqliteEntityMigrationsSqlGenerator>();
            optionsBuilder.BaseOptionsBuilder.ReplaceService <ISqlGenerationHelper, SqliteEntitySqlGenerationHelper>();

            return(optionsBuilder.UseDatabaseProviderFeatures <SqliteEntityDatabaseFeatures>()
                   .ApplyServices(services =>
            {
                services.AddScoped <IPluginHistoryRepository, SqlitePluginHistoryRepository>();
            }));
        }
Beispiel #3
0
        /// <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);
        }
Beispiel #4
0
 /// <summary>
 /// Creates a new instance of the <see cref="EntityDbContextOptionsExtension"/> class.
 /// </summary>
 /// <param name="baseOptionsBuilder">The base options builder.</param>
 public EntityDbContextOptionsExtension(DbContextOptionsBuilder baseOptionsBuilder)
 {
     Builder = new EntityDbContextOptionsBuilder(baseOptionsBuilder);
 }