Skip to content

bit Besql dbContext must be able to resolve scoped services #11775

@ysmoradi

Description

@ysmoradi

To enable the bit Besql DbContext to resolve scoped services, the current usage of PooledDbContextFactory should be replaced with IDbContextFactory<TContext>.

Motivation:

The core configuration of CommunityToolkit.Datasync.Client takes place in an overridden method of the DbContext called OnDatasyncInitialization.
During the execution of this method, various HttpMessageHandler instances must be provided to allow the client to communicate with the server, for example, handlers that automatically append an access token, refresh it when expired, etc.

These handlers are typically registered as scoped services.
The PooledDbContextFactory creates DbContext instances from an internal pool that operates at the application (singleton) level, meaning it cannot resolve scoped dependencies. As a result, the current bit Besql DbContext implementation fails to inject these scoped HTTP message handlers.

Switching to IDbContextFactory<TContext> resolves the DbContext within the current dependency-injection scope, allowing all scoped services "including authentication-related HTTP handlers" to be injected correctly.

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions