Skip to content
Docs Try Aspire

AspireEFSqliteExtensions Methods

Class Methods 1 member
Extension methods for configuring Sqlite with Entity Framework Core.
AddSqliteDbContext(IHostApplicationBuilder, string, Action<SqliteEntityFrameworkCoreSettings>, Action<DbContextOptionsBuilder>) Section titled AddSqliteDbContext(IHostApplicationBuilder, string, Action<SqliteEntityFrameworkCoreSettings>, Action<DbContextOptionsBuilder>) extension
Registers the TContext as a scoped service in the services provided by the builder.
public static class AspireEFSqliteExtensions
{
public static void AddSqliteDbContext<TContext>(
this IHostApplicationBuilder builder,
string name,
Action<SqliteEntityFrameworkCoreSettings>? configureSettings = null,
Action<DbContextOptionsBuilder>? configureDbContextOptions = null)
{
// ...
}
}
builder IHostApplicationBuilder The Hosting.IHostApplicationBuilder to read config from and add services to.
name string A name used to retrieve the connection string from the ConnectionStrings configuration section.
configureSettings Action<SqliteEntityFrameworkCoreSettings> optional An optional delegate that can be used for customizing options. It's invoked after the settings are read from the configuration.
configureDbContextOptions Action<DbContextOptionsBuilder> optional An optional method that can be used for customizing the EntityFrameworkCore.DbContextOptionsBuilder`1.
ArgumentNullException Thrown if mandatory builder is null.
InvalidOperationException Thrown when mandatory SqliteEntityFrameworkCoreSettings.ConnectionString is not provided.

Reads the configuration from "Aspire:Sqlite:EntityFrameworkCore:Sqlite:{typeof(TContext).Name}" config section, or "Aspire:Sqlite:EntityFrameworkCore:Sqlite" if former does not exist.

The DbContext.OnConfiguring method can then be overridden to configure EntityFrameworkCore.DbContext options.