Skip to main content
All docs
V25.1
  • .NET 8.0+
    • The page you are viewing does not exist in the .NET Framework 4.6.2+ platform documentation. This link will take you to the parent topic of the current section.

    DbContextServiceBasedBuilder<TContext>.WithDbContext<TDbContext>(Action<IServiceProvider, DbContextOptionsBuilder>, ServiceLifetime) Method

    Allows you to configure specified DbContext.

    Namespace: DevExpress.ExpressApp.ApplicationBuilder

    Assembly: DevExpress.ExpressApp.EFCore.v25.1.dll

    NuGet Package: DevExpress.ExpressApp.EFCore

    Declaration

    public IObjectSpaceProviderServiceBasedBuilder<TContext> WithDbContext<TDbContext>(
        Action<IServiceProvider, DbContextOptionsBuilder> configureOptions,
        ServiceLifetime dbContextFactoryServiceLifetime = ServiceLifetime.Scoped
    )
        where TDbContext : DbContext

    Parameters

    Name Type Description
    configureOptions Action<IServiceProvider, DbContextOptionsBuilder>

    A delegate that configures DbContext.

    Optional Parameters

    Name Type Default Description
    dbContextFactoryServiceLifetime ServiceLifetime Scoped

    A ServiceLifetime enumeration value that specifies the lifetime of the DbContextFactory service registered by the method.

    Type Parameters

    Name Description
    TDbContext

    The type of a DbContext object.

    Returns

    Type Description
    IObjectSpaceProviderServiceBasedBuilder<TContext>

    Allows you to register and configure Object Space Providers in your application, and chain further provider registrations.

    Remarks

    The following example demonstrates how to use this method:

    File: MySolution.Blazor.Server\Startup.cs.

    using DevExpress.ExpressApp.ApplicationBuilder;
    using DevExpress.ExpressApp.Blazor.ApplicationBuilder;
    // ...
    public class Startup {
       // ...
        public void ConfigureServices(IServiceCollection services) {
            // ...
            services.AddXaf(Configuration, builder => {
                builder.UseApplication<MySolutionBlazorApplication>();
                builder.ObjectSpaceProviders
                    // ...
                    .AddSecuredEFCore()
                    .WithDbContext<MySolutionDbContext>((serviceProvider, options) => {
                        // ...
                    },ServiceLifetime.Transient);
            });
            // ...
        }
    }
    
    See Also