# AspireEFSqliteExtensions Methods

- Package: [CommunityToolkit.Aspire.Microsoft.EntityFrameworkCore.Sqlite](/reference/api/csharp/communitytoolkit.aspire.microsoft.entityframeworkcore.sqlite.md)
- Type: [AspireEFSqliteExtensions](/reference/api/csharp/communitytoolkit.aspire.microsoft.entityframeworkcore.sqlite/aspireefsqliteextensions.md)
- Kind: `Methods`
- Members: `1`

Extension methods for configuring Sqlite with Entity Framework Core.

## AddSqliteDbContext(IHostApplicationBuilder, string, Action<SqliteEntityFrameworkCoreSettings>, Action<DbContextOptionsBuilder>)

- Name: `AddSqliteDbContext(IHostApplicationBuilder, string, Action<SqliteEntityFrameworkCoreSettings>, Action<DbContextOptionsBuilder>)`
- Modifiers: `extension`
- Source: [GitHub](https://github.com/CommunityToolkit/Aspire/blob/c7dedf100938dcdcc84f8348ea76032f1fd180b5/src/CommunityToolkit.Aspire.Microsoft.EntityFrameworkCore.Sqlite/AspireEFSqliteExtensions.cs#L43-L74)

Registers the `TContext` as a scoped service in the services provided by the `builder`.

```csharp
public static class AspireEFSqliteExtensions
{
    public static void AddSqliteDbContext<TContext>(
        this IHostApplicationBuilder builder,
        string name,
        Action<SqliteEntityFrameworkCoreSettings>? configureSettings = null,
        Action<DbContextOptionsBuilder>? configureDbContextOptions = null)
    {
        // ...
    }
}
```

## Parameters

- `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`.

## Exceptions

- `ArgumentNullException` -- Thrown if mandatory `builder` is null.
- `InvalidOperationException` -- Thrown when mandatory [SqliteEntityFrameworkCoreSettings.ConnectionString](/reference/api/csharp/communitytoolkit.aspire.microsoft.entityframeworkcore.sqlite/sqliteentityframeworkcoresettings/properties.md#connectionstring) is not provided.

## Remarks

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.
