Base solution for your next web application

Activities of "maliming"

: )

hi @uxabp,

Can you try the code below?


//Add these lines to your ef core module Initialize method.
var adapter = new AbpDevExtremeAsyncAdapter();
CustomAsyncAdapters.RegisterAdapter(typeof(AbpEntityQueryProvider), adapter);
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using DevExtreme.AspNet.Data.Async;

namespace Abp.EntityFrameworkCore;

public class AbpDevExtremeAsyncAdapter : IAsyncAdapter
{
    private readonly MethodInfo _countAsyncMethod;
    private readonly MethodInfo _toListAsyncMethod;

    public AbpDevExtremeAsyncAdapter()
    {
        var extensionsType = Type.GetType("Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions, Microsoft.EntityFrameworkCore");
        _countAsyncMethod = FindQueryExtensionMethod(extensionsType, "CountAsync");
        _toListAsyncMethod = FindQueryExtensionMethod(extensionsType, "ToListAsync");
    }

    public Task<int> CountAsync(IQueryProvider provider, Expression expr, CancellationToken cancellationToken)
    {
        return InvokeCountAsync(_countAsyncMethod, provider, expr, cancellationToken);
    }

    public Task<IEnumerable<T>> ToEnumerableAsync<T>(IQueryProvider provider, Expression expr, CancellationToken cancellationToken)
    {
        return InvokeToListAsync<T>(_toListAsyncMethod, provider, expr, cancellationToken);
    }

    static MethodInfo FindQueryExtensionMethod(Type extensionsType, string name)
    {
        return extensionsType.GetMethods().First(m =>
        {
            if (!m.IsGenericMethod || m.Name != name)
            {
                return false;
            }
            var parameters = m.GetParameters();
            return parameters.Length == 2 && parameters[1].ParameterType == typeof(CancellationToken);
        });
    }

    static Task<int> InvokeCountAsync(MethodInfo method, IQueryProvider provider, Expression expr, CancellationToken cancellationToken)
    {
        var countArgument = ((MethodCallExpression)expr).Arguments[0];
        var query = provider.CreateQuery(countArgument);
        return (Task<int>)InvokeQueryExtensionMethod(method, query.ElementType, query, cancellationToken);
    }

    static async Task<IEnumerable<T>> InvokeToListAsync<T>(MethodInfo method, IQueryProvider provider, Expression expr, CancellationToken cancellationToken)
    {
        return await (Task<List<T>>)InvokeQueryExtensionMethod(method, typeof(T), provider.CreateQuery(expr), cancellationToken);
    }

    static object InvokeQueryExtensionMethod(MethodInfo method, Type elementType, IQueryable query, CancellationToken cancellationToken)
    {
        return method.MakeGenericMethod(elementType).Invoke(null, new object[] { query, cancellationToken });
    }
}

hi

can you explain why the method should be virtual for it to work?

Castle Windsor's interceptor can only intercept:

  1. All public or public virtual methods for classes that are used over an interface (Like an application service used over a service interface).
  2. All public virtual methods for self-injected classes (Like MVC Controllers and Web API Controllers).
  3. All protected virtual methods.

Because application services will use classes as MVC controllers, virtual methods are needed.

I wasn't expecting virtual, cause for AbpAuthorize we do not need to make it virtual. Can you elaborate on that?

Abp also uses MVC filters to intercept method calls. It does not require virtual methods. It is only suitable for controllers or Pages.

https://github.com/aspnetboilerplate/aspnetboilerplate/blob/dev/src/Abp.AspNetCore/AspNetCore/Mvc/Authorization/AbpAuthorizationFilter.cs#L54

hi

Please make the GetOffers method virtual. in this way the Interceptor will works.

public virtual async Task<GetOffersForMobileOutput> GetOffers(GetOffersForMobileInput input)

unAuthorizedRequest will be true when AbpAuthorizationException happened. this is by design,

hi

I got your project, Please share some necessary steps, Thanks.

hi cangunaydin

Can you share a project and steps to reproduce the problem? [email protected]

You can copy your code to the demo project.

hi cangunaydin

I don't think you need to create additional interceptors and attributes. You can continue to use abpauthorize, you need to try to authenticate the second jwt in startup.

app.UseAuthentication();
app.UseJwtTokenMiddleware();
app.UseJwtTokenMiddleware("AssociateBearer");

The ConfigureServices method of startup class.

services.PostConfigure<MvcOptions>(mvcOptions =>
{
    mvcOptions.Conventions.RemoveType<AbpAppServiceConvention>();
    mvcOptions.Conventions.Add(new MyAbpAppServiceConvention(services));
});

The MyAbpAppServiceConvention: https://gist.github.com/maliming/b252b1cf23db538769e87f7434945057

hi

Can you try to the code of this PR? https://github.com/aspnetboilerplate/aspnetboilerplate/pull/6114

Answer

hi kansoftware

There is no sample at the moment, you can try to get help on Google or identity server community.

Showing 1 to 10 of 2993 entries