Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DataGrid] Make EntityFrameworkAsyncQueryExecutor inheritable #3272

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,23 +1,34 @@
// ------------------------------------------------------------------------
// MIT License - Copyright (c) Microsoft Corporation. All rights reserved.
// ------------------------------------------------------------------------

using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Query;
using Microsoft.FluentUI.AspNetCore.Components.DataGrid.Infrastructure;

namespace Microsoft.FluentUI.AspNetCore.Components.DataGrid.EntityFrameworkAdapter;

internal class EntityFrameworkAsyncQueryExecutor : IAsyncQueryExecutor, IDisposable
/// <summary>
/// An <see cref="IAsyncQueryExecutor"/> implementation for Entity Framework Core.
/// </summary>
public class EntityFrameworkAsyncQueryExecutor : IAsyncQueryExecutor, IDisposable
{
private readonly SemaphoreSlim _lock = new(1);

/// <inheritdoc />
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to add virtual for these public properties ?

Copy link
Contributor

@miguelhasse miguelhasse Feb 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think they should be made virtual. If someone would have the need to override these, than they should probably be looking just implementing a whole different version of this IAsyncQueryExecutor.

Copy link
Collaborator

@dvoituron dvoituron Feb 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the PR description must be updated. Now "Make the EntityFrameworkAsyncQueryExecutor class public so that it can be inherited"

I thought that was the goal of this PR: to allow inheritance 🙃

public bool IsSupported<T>(IQueryable<T> queryable)
=> queryable.Provider is IAsyncQueryProvider;

/// <inheritdoc />
public Task<int> CountAsync<T>(IQueryable<T> queryable, CancellationToken cancellationToken)
=> ExecuteAsync(() => queryable.CountAsync(cancellationToken));

/// <inheritdoc />
public Task<T[]> ToArrayAsync<T>(IQueryable<T> queryable, CancellationToken cancellationToken)
=> ExecuteAsync(() => queryable.ToArrayAsync(cancellationToken));

private async Task<TResult> ExecuteAsync<TResult>(Func<Task<TResult>> operation)
/// <inheritdoc />
protected virtual async Task<TResult> ExecuteAsync<TResult>(Func<Task<TResult>> operation)
{
try
{
Expand Down
15 changes: 14 additions & 1 deletion src/Extensions/DataGrid.EntityFrameworkAdapter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,25 @@ Install the package by running the command:
dotnet add package Microsoft.FluentUI.AspNetCore.Components.DataGrid.EntityFrameworkAdapter
```

## Creating a derived AsyncQueryExecutor implementation
Starting with v4.11.4, the `EntityFrameworkAsyncQueryExecutor` class is made public
so that you can derive from it and override the `ExecuteAsync` method to provide
custom query execution logic. This is useful if you want to add custom query processing
logic, such as logging, caching, or query translation or if you want specific [error handling](https://github.com/microsoft/fluentui-blazor/issues/3269).

## Usage
In your Program.cs file you need to add the following:
When using the provided implementation, you need to add add the following in the `Program.cs` file:

```
builder.Services.AddDataGridEntityFrameworkAdapter();
```

When using a custom implementation, you need to add this custom implementation to the DI container in the `Program.cs` file yourself.
You do **not** call `AddDataGridEntityFrameworkAdapter` in this case.
```
builder.Services.AddScoped<IAsyncQueryExecutor, MyCustomAsyncQueryExecutor>();
```

## Support
The Microsoft Fluent UI Blazor library is an open source project and is **not** an official part of ASP.NET Core, which means it’s **not** officially
supported and isn’t committed to ship updates as part of any official .NET updates. It is built and maintained by Microsoft employees (**and** other contributors)
Expand Down
Loading