/// <summary> /// Configures the context to connect to a named in-memory database. /// The in-memory database is shared anywhere the same name is used, but only for a given /// service provider. /// </summary> /// <param name="optionsBuilder"> The builder being used to configure the context. </param> /// <param name="databaseName"> /// The name of the in-memory database. This allows the scope of the in-memory database to be controlled /// independently of the context. The in-memory database is shared anywhere the same name is used. /// </param> /// <param name="databaseRoot"> /// All in-memory databases will be rooted in this object, allowing the application /// to control their lifetime. This is useful when sometimes the context instance /// is created explicitly with <c>new</c> while at other times it is resolved using dependency injection. /// </param> /// <param name="inMemoryOptionsAction">An optional action to allow additional in-memory specific configuration.</param> /// <returns> The options builder so that further configuration can be chained. </returns> public static DbContextOptionsBuilder UseLiteDB( [NotNull] this DbContextOptionsBuilder optionsBuilder, [NotNull] string databaseName, [CanBeNull] LiteDBDatabaseRoot databaseRoot, [CanBeNull] Action <LiteDBDbContextOptionsBuilder> inMemoryOptionsAction = null) { Check.NotNull(optionsBuilder, nameof(optionsBuilder)); Check.NotEmpty(databaseName, nameof(databaseName)); var extension = optionsBuilder.Options.FindExtension <LiteDBOptionsExtension>() ?? new LiteDBOptionsExtension(); extension = extension.WithStoreName(databaseName); if (databaseRoot != null) { extension = extension.WithDatabaseRoot(databaseRoot); } ConfigureWarnings(optionsBuilder); ((IDbContextOptionsBuilderInfrastructure)optionsBuilder).AddOrUpdateExtension(extension); inMemoryOptionsAction?.Invoke(new LiteDBDbContextOptionsBuilder(optionsBuilder)); return(optionsBuilder); }
/// <summary> /// This API supports the Entity Framework Core infrastructure and is not intended to be used /// directly from your code. This API may change or be removed in future releases. /// </summary> public virtual LiteDBOptionsExtension WithDatabaseRoot([NotNull] LiteDBDatabaseRoot databaseRoot) { var clone = Clone(); clone._databaseRoot = databaseRoot; return(clone); }
/// <summary> /// Configures the context to connect to an in-memory database. /// The in-memory database is shared anywhere the same name is used, but only for a given /// service provider. /// </summary> /// <typeparam name="TContext"> The type of context being configured. </typeparam> /// <param name="optionsBuilder"> The builder being used to configure the context. </param> /// <param name="databaseName"> /// The name of the in-memory database. This allows the scope of the in-memory database to be controlled /// independently of the context. The in-memory database is shared anywhere the same name is used. /// </param> /// <param name="databaseRoot"> /// All in-memory databases will be rooted in this object, allowing the application /// to control their lifetime. This is useful when sometimes the context instance /// is created explicitly with <c>new</c> while at other times it is resolved using dependency injection. /// </param> /// <param name="inMemoryOptionsAction">An optional action to allow additional in-memory specific configuration.</param> /// <returns> The options builder so that further configuration can be chained. </returns> public static DbContextOptionsBuilder <TContext> UseLiteDB <TContext>( [NotNull] this DbContextOptionsBuilder <TContext> optionsBuilder, [NotNull] string databaseName, [CanBeNull] LiteDBDatabaseRoot databaseRoot, [CanBeNull] Action <LiteDBDbContextOptionsBuilder> inMemoryOptionsAction = null) where TContext : DbContext => (DbContextOptionsBuilder <TContext>)UseLiteDB( (DbContextOptionsBuilder)optionsBuilder, databaseName, databaseRoot, inMemoryOptionsAction);
/// <summary> /// This API supports the Entity Framework Core infrastructure and is not intended to be used /// directly from your code. This API may change or be removed in future releases. /// </summary> protected LiteDBOptionsExtension([NotNull] LiteDBOptionsExtension copyFrom) { _storeName = copyFrom._storeName; _databaseRoot = copyFrom._databaseRoot; }