Table of Contents

Class CoreOptionsExtension

Namespace
Microsoft.EntityFrameworkCore.Infrastructure
Assembly
Microsoft.EntityFrameworkCore.dll

Represents options managed by the core of Entity Framework, as opposed to those managed by database providers or extensions. These options are set using DbContextOptionsBuilder.

Instances of this class are designed to be immutable. To change an option, call one of the 'With...' methods to obtain a new instance with the option changed.

public class CoreOptionsExtension : IDbContextOptionsExtension
Inheritance
CoreOptionsExtension
Implements
Inherited Members

Remarks

See Implementation of database providers and extensions for more information and examples.

Constructors

CoreOptionsExtension()

Creates a new set of options with everything set to default values.

public CoreOptionsExtension()

CoreOptionsExtension(CoreOptionsExtension)

Called by a derived class constructor when implementing the Clone() method.

protected CoreOptionsExtension(CoreOptionsExtension copyFrom)

Parameters

copyFrom CoreOptionsExtension

The instance that is being cloned.

Properties

ApplicationServiceProvider

The option set from the UseApplicationServiceProvider(IServiceProvider?) method.

public virtual IServiceProvider? ApplicationServiceProvider { get; }

Property Value

IServiceProvider

AutoResolveRootProvider

public virtual bool AutoResolveRootProvider { get; }

Property Value

bool

DbContextLogger

public virtual IDbContextLogger? DbContextLogger { get; }

Property Value

IDbContextLogger

DetailedErrorsEnabled

The option set from the EnableDetailedErrors(bool) method.

public virtual bool DetailedErrorsEnabled { get; }

Property Value

bool

Info

Information/metadata about the extension.

public virtual DbContextOptionsExtensionInfo Info { get; }

Property Value

DbContextOptionsExtensionInfo

Interceptors

The options set from the AddInterceptors(IEnumerable<IInterceptor>) method for scoped interceptors.

public virtual IEnumerable<IInterceptor>? Interceptors { get; }

Property Value

IEnumerable<IInterceptor>

InternalServiceProvider

The option set from the UseInternalServiceProvider(IServiceProvider?) method.

public virtual IServiceProvider? InternalServiceProvider { get; }

Property Value

IServiceProvider

IsSensitiveDataLoggingEnabled

The option set from the EnableSensitiveDataLogging(bool) method.

public virtual bool IsSensitiveDataLoggingEnabled { get; }

Property Value

bool

LoggerFactory

The option set from the UseLoggerFactory(ILoggerFactory?) method.

public virtual ILoggerFactory? LoggerFactory { get; }

Property Value

ILoggerFactory

LoggingCacheTime

public virtual TimeSpan LoggingCacheTime { get; }

Property Value

TimeSpan

MaxPoolSize

public virtual int? MaxPoolSize { get; }

Property Value

int?

MemoryCache

The option set from the UseMemoryCache(IMemoryCache?) method.

public virtual IMemoryCache? MemoryCache { get; }

Property Value

IMemoryCache

Model

The option set from the UseModel(IModel) method.

public virtual IModel? Model { get; }

Property Value

IModel

QueryTrackingBehavior

The option set from the UseQueryTrackingBehavior(QueryTrackingBehavior) method.

public virtual QueryTrackingBehavior QueryTrackingBehavior { get; }

Property Value

QueryTrackingBehavior

ReplacedServices

The options set from the ReplaceService<TService, TImplementation>() method.

public virtual IReadOnlyDictionary<(Type, Type?), Type>? ReplacedServices { get; }

Property Value

IReadOnlyDictionary<(Type, Type), Type>

RootApplicationServiceProvider

public virtual IServiceProvider? RootApplicationServiceProvider { get; }

Property Value

IServiceProvider

ServiceProviderCachingEnabled

The option set from the EnableServiceProviderCaching(bool) method.

public virtual bool ServiceProviderCachingEnabled { get; }

Property Value

bool

SingletonInterceptors

The options set from the AddInterceptors(IEnumerable<IInterceptor>) method for singleton interceptors.

public virtual IEnumerable<ISingletonInterceptor>? SingletonInterceptors { get; }

Property Value

IEnumerable<ISingletonInterceptor>

ThreadSafetyChecksEnabled

The option set from the EnableThreadSafetyChecks(bool) method.

public virtual bool ThreadSafetyChecksEnabled { get; }

Property Value

bool

WarningsConfiguration

public virtual WarningsConfiguration WarningsConfiguration { get; }

Property Value

WarningsConfiguration

Methods

ApplyServices(IServiceCollection)

Adds the services required to make the selected options work. This is used when there is no external IServiceProvider and EF is maintaining its own service provider internally. This allows database providers (and other extensions) to register their required services when EF is creating an service provider.

public virtual void ApplyServices(IServiceCollection services)

Parameters

services IServiceCollection

The collection to add services to.

Clone()

Override this method in a derived class to ensure that any clone created is also of that class.

protected virtual CoreOptionsExtension Clone()

Returns

CoreOptionsExtension

A clone of this instance, which can be modified before being returned as immutable.

Validate(IDbContextOptions)

Gives the extension a chance to validate that all options in the extension are valid. If options are invalid, then an exception will be thrown.

public virtual void Validate(IDbContextOptions options)

Parameters

options IDbContextOptions

The options being validated.

WithApplicationServiceProvider(IServiceProvider?)

Creates a new instance with all options the same as for this instance, but with the given option changed. It is unusual to call this method directly. Instead use DbContextOptionsBuilder.

public virtual CoreOptionsExtension WithApplicationServiceProvider(IServiceProvider? applicationServiceProvider)

Parameters

applicationServiceProvider IServiceProvider

The option to change.

Returns

CoreOptionsExtension

A new instance with the option changed.

WithDbContextLogger(IDbContextLogger?)

Creates a new instance with all options the same as for this instance, but with the given option changed. It is unusual to call this method directly. Instead use DbContextOptionsBuilder.

public virtual CoreOptionsExtension WithDbContextLogger(IDbContextLogger? contextLogger)

Parameters

contextLogger IDbContextLogger

The option to change.

Returns

CoreOptionsExtension

A new instance with the option changed.

WithDetailedErrorsEnabled(bool)

Creates a new instance with all options the same as for this instance, but with the given option changed. It is unusual to call this method directly. Instead use DbContextOptionsBuilder.

public virtual CoreOptionsExtension WithDetailedErrorsEnabled(bool detailedErrorsEnabled)

Parameters

detailedErrorsEnabled bool

The option to change.

Returns

CoreOptionsExtension

A new instance with the option changed.

WithInterceptors(IEnumerable<IInterceptor>)

Creates a new instance with all options the same as for this instance, but with the given option changed. It is unusual to call this method directly. Instead use DbContextOptionsBuilder.

public virtual CoreOptionsExtension WithInterceptors(IEnumerable<IInterceptor> interceptors)

Parameters

interceptors IEnumerable<IInterceptor>

The option to change.

Returns

CoreOptionsExtension

A new instance with the option changed.

WithInternalServiceProvider(IServiceProvider?)

Creates a new instance with all options the same as for this instance, but with the given option changed. It is unusual to call this method directly. Instead use DbContextOptionsBuilder.

public virtual CoreOptionsExtension WithInternalServiceProvider(IServiceProvider? internalServiceProvider)

Parameters

internalServiceProvider IServiceProvider

The option to change.

Returns

CoreOptionsExtension

A new instance with the option changed.

WithLoggerFactory(ILoggerFactory?)

Creates a new instance with all options the same as for this instance, but with the given option changed. It is unusual to call this method directly. Instead use DbContextOptionsBuilder.

public virtual CoreOptionsExtension WithLoggerFactory(ILoggerFactory? loggerFactory)

Parameters

loggerFactory ILoggerFactory

The option to change.

Returns

CoreOptionsExtension

A new instance with the option changed.

WithLoggingCacheTime(TimeSpan)

Creates a new instance with all options the same as for this instance, but with the given option changed. It is unusual to call this method directly. Instead use DbContextOptionsBuilder.

public virtual CoreOptionsExtension WithLoggingCacheTime(TimeSpan timeSpan)

Parameters

timeSpan TimeSpan

The maximum time period over which to skip logging checks before checking again.

Returns

CoreOptionsExtension

A new instance with the option changed.

WithMaxPoolSize(int?)

Creates a new instance with all options the same as for this instance, but with the given option changed. It is unusual to call this method directly. Instead use DbContextOptionsBuilder.

public virtual CoreOptionsExtension WithMaxPoolSize(int? maxPoolSize)

Parameters

maxPoolSize int?

The option to change.

Returns

CoreOptionsExtension

A new instance with the option changed.

WithMemoryCache(IMemoryCache?)

Creates a new instance with all options the same as for this instance, but with the given option changed. It is unusual to call this method directly. Instead use DbContextOptionsBuilder.

public virtual CoreOptionsExtension WithMemoryCache(IMemoryCache? memoryCache)

Parameters

memoryCache IMemoryCache

The option to change.

Returns

CoreOptionsExtension

A new instance with the option changed.

WithModel(IModel?)

Creates a new instance with all options the same as for this instance, but with the given option changed. It is unusual to call this method directly. Instead use DbContextOptionsBuilder.

public virtual CoreOptionsExtension WithModel(IModel? model)

Parameters

model IModel

The option to change.

Returns

CoreOptionsExtension

A new instance with the option changed.

WithQueryTrackingBehavior(QueryTrackingBehavior)

Creates a new instance with all options the same as for this instance, but with the given option changed. It is unusual to call this method directly. Instead use DbContextOptionsBuilder.

public virtual CoreOptionsExtension WithQueryTrackingBehavior(QueryTrackingBehavior queryTrackingBehavior)

Parameters

queryTrackingBehavior QueryTrackingBehavior

The option to change.

Returns

CoreOptionsExtension

A new instance with the option changed.

WithReplacedService(Type, Type, Type?)

Creates a new instance with all options the same as for this instance, but with the given option changed. It is unusual to call this method directly. Instead use DbContextOptionsBuilder.

public virtual CoreOptionsExtension WithReplacedService(Type serviceType, Type newImplementationType, Type? currentImplementationType = null)

Parameters

serviceType Type

The service contract.

newImplementationType Type

The implementation type to use for the service.

currentImplementationType Type

The specific existing implementation type to replace.

Returns

CoreOptionsExtension

A new instance with the option changed.

WithRootApplicationServiceProvider(bool)

Creates a new instance with all options the same as for this instance, but with the given option changed. It is unusual to call this method directly. Instead use DbContextOptionsBuilder.

public virtual CoreOptionsExtension WithRootApplicationServiceProvider(bool autoResolve = true)

Parameters

autoResolve bool

The option to change.

Returns

CoreOptionsExtension

A new instance with the option changed.

WithRootApplicationServiceProvider(IServiceProvider?)

Creates a new instance with all options the same as for this instance, but with the given option changed. It is unusual to call this method directly. Instead use DbContextOptionsBuilder.

public virtual CoreOptionsExtension WithRootApplicationServiceProvider(IServiceProvider? rootApplicationServiceProvider)

Parameters

rootApplicationServiceProvider IServiceProvider

The option to change.

Returns

CoreOptionsExtension

A new instance with the option changed.

WithSensitiveDataLoggingEnabled(bool)

Creates a new instance with all options the same as for this instance, but with the given option changed. It is unusual to call this method directly. Instead use DbContextOptionsBuilder.

public virtual CoreOptionsExtension WithSensitiveDataLoggingEnabled(bool sensitiveDataLoggingEnabled)

Parameters

sensitiveDataLoggingEnabled bool

The option to change.

Returns

CoreOptionsExtension

A new instance with the option changed.

WithServiceProviderCachingEnabled(bool)

Creates a new instance with all options the same as for this instance, but with the given option changed. It is unusual to call this method directly. Instead use DbContextOptionsBuilder.

public virtual CoreOptionsExtension WithServiceProviderCachingEnabled(bool serviceProviderCachingEnabled)

Parameters

serviceProviderCachingEnabled bool

The option to change.

Returns

CoreOptionsExtension

A new instance with the option changed.

WithSingletonInterceptors(IEnumerable<ISingletonInterceptor>)

Creates a new instance with all options the same as for this instance, but with the given option changed. It is unusual to call this method directly. Instead use DbContextOptionsBuilder.

public virtual CoreOptionsExtension WithSingletonInterceptors(IEnumerable<ISingletonInterceptor> interceptors)

Parameters

interceptors IEnumerable<ISingletonInterceptor>

The option to change.

Returns

CoreOptionsExtension

A new instance with the option changed.

WithThreadSafetyChecksEnabled(bool)

Creates a new instance with all options the same as for this instance, but with the given option changed. It is unusual to call this method directly. Instead use DbContextOptionsBuilder.

public virtual CoreOptionsExtension WithThreadSafetyChecksEnabled(bool checksEnabled)

Parameters

checksEnabled bool

The option to change.

Returns

CoreOptionsExtension

A new instance with the option changed.

WithWarningsConfiguration(WarningsConfiguration)

Creates a new instance with all options the same as for this instance, but with the given option changed. It is unusual to call this method directly. Instead use DbContextOptionsBuilder.

public virtual CoreOptionsExtension WithWarningsConfiguration(WarningsConfiguration warningsConfiguration)

Parameters

warningsConfiguration WarningsConfiguration

The option to change.

Returns

CoreOptionsExtension

A new instance with the option changed.