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

AuditedDbContextBuilderExtensions.WithAuditedDbContext<TContext>(DbContextBuilder<TContext>, Action<AuditedDbContextConfigurator>, ServiceLifetime) Method

Allows you to configure the main (business object) and additional (audit history) DbContext objects in WinForms applications with the Audit Trail Module.

Namespace: DevExpress.ExpressApp.ApplicationBuilder

Assembly: DevExpress.ExpressApp.AuditTrail.EFCore.v23.2.dll

NuGet Package: DevExpress.ExpressApp.AuditTrail.EFCore

Declaration

public static IObjectSpaceProviderBuilder<TContext> WithAuditedDbContext<TContext>(
    this DbContextBuilder<TContext> dbContextBuilder,
    Action<AuditedDbContextConfigurator> configureContexts,
    ServiceLifetime dbContextFactoryServiceLifetime = ServiceLifetime.Scoped
)
    where TContext : IXafApplicationBuilder<TContext>, IAccessor<IServiceCollection>

Parameters

Name Type Description
dbContextBuilder DbContextBuilder<TContext>

Allows you to configure DbContext objects.

configureContexts Action<AuditedDbContextConfigurator>

A delegate that configures DbContext objects.

Optional Parameters

Name Type Default Description
dbContextFactoryServiceLifetime ServiceLifetime Scoped

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

Type Parameters

Name Description
TContext

The IWinApplicationBuilder type.

Returns

Type Description
IObjectSpaceProviderBuilder<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.Win\Startup.cs.

using DevExpress.ExpressApp.ApplicationBuilder;
using DevExpress.ExpressApp.Win.ApplicationBuilder;
// ...
public class ApplicationBuilder : IDesignTimeApplicationFactory {
    public static WinApplication BuildApplication(string connectionString) {
        var builder = WinApplication.CreateBuilder();
        builder.UseApplication<MySolutionWindowsFormsApplication>();
        builder.ObjectSpaceProviders
            .AddSecuredEFCore()
            .WithAuditedDbContext(contexts => {
                contexts.Configure<MySolutionDbContext, AuditingDbContext>(
                    (application, businessObjectDbContextOptions) => {
                        // ...
                    },
                    (application, auditHistoryDbContextOptions) => {
                        // ...
                    },
                    options => {
                        // ...
                    });
            });
    }
    // ...
}
See Also