Skip to content
DocsTry Aspire
DocsTry

AspireEFSqliteExtensions Methods

ClassMethods1 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)
{
// ...
}
}
builderIHostApplicationBuilderThe Hosting.IHostApplicationBuilder to read config from and add services to.
namestringA name used to retrieve the connection string from the ConnectionStrings configuration section.
configureSettingsAction<SqliteEntityFrameworkCoreSettings>optionalAn optional delegate that can be used for customizing options. It's invoked after the settings are read from the configuration.
configureDbContextOptionsAction<DbContextOptionsBuilder>optionalAn optional method that can be used for customizing the EntityFrameworkCore.DbContextOptionsBuilder`1.
ArgumentNullExceptionThrown if mandatory builder is null.
InvalidOperationExceptionThrown 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.