أنشطة "Denis"

سؤال

I need to get language which passed via Accept-language header to endpoint. In aspbloilerplate I used Thread.CurrentThread.CurrentUICulture . In abp it does not look working.

What way I need to apply?

  • ABP Framework version: v4.3.0
  • UI type: Angular
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): yes
  • Exception message and stack trace:
  • Steps to reproduce the issue:"
سؤال

I am trying to run service for MSA solution. Service can not start with messages in log

[15:26:22 ERR] ABP-LIC-0008 - License check failed for 'Volo.Saas.Domain-v4.4.0.0'.
You need to log in using the command `abp login <username>`.
For more information, contact to license@abp.io.
[15:26:25 WRN] The AMQP operation was interrupted: AMQP close-reason, initiated by Application, code=200, text='Connection close forced', classId=0, methodId=0
RabbitMQ.Client.Exceptions.OperationInterruptedException: The AMQP operation was interrupted: AMQP close-reason, initiated by Application, code=200, text='Connection close forced', classId=0, methodId=0
   at RabbitMQ.Client.Impl.SimpleBlockingRpcContinuation.GetReply(TimeSpan timeout)
   at RabbitMQ.Client.Impl.ModelBase.QueueDeclare(String queue, Boolean passive, Boolean durable, Boolean exclusive, Boolean autoDelete, IDictionary`2 arguments)
   at RabbitMQ.Client.Impl.ModelBase.QueueDeclare(String queue, Boolean durable, Boolean exclusive, Boolean autoDelete, IDictionary`2 arguments)
   at RabbitMQ.Client.Impl.AutorecoveringModel.QueueDeclare(String queue, Boolean durable, Boolean exclusive, Boolean autoDelete, IDictionary`2 arguments)
   at RabbitMQ.Client.IModelExensions.QueueDeclare(IModel model, String queue, Boolean durable, Boolean exclusive, Boolean autoDelete, IDictionary`2 arguments)
   at Volo.Abp.RabbitMQ.RabbitMqMessageConsumer.TryCreateChannelAsync()
[15:26:25 INF] Application is shutting down...
[15:26:25 INF] Initialized all ABP modules.
[15:26:25 FTL] Unable to start Kestrel.
System.Threading.Tasks.TaskCanceledException: A task was canceled.
   at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerImpl.BindAsync(CancellationToken cancellationToken)
   at Microsoft.AspNetCore.Server.Kestrel.Core.KestrelServerImpl.StartAsync[TContext](IHttpApplication`1 application, CancellationToken cancellationToken)

Why it is asking to log in into abp, whne license key is provided actually?

  • ABP Framework version: v4.3
  • UI type: Angular
  • DB provider: EF Core
  • Tiered (MVC) or Identity Server Separated (Angular): yes

I need t configure DB context to use this library https://github.com/VahidN/EFCoreSecondLevelCacheInterceptor

How I can do that in ABP?

The code below is used to enable this interceptor

public static class MsSqlServiceCollectionExtensions
    {
        public static IServiceCollection AddConfiguredMsSqlDbContext(this IServiceCollection services, string connectionString)
        {
            services.AddDbContextPool<ApplicationDbContext>((serviceProvider, optionsBuilder) =>
                    optionsBuilder
                        .UseSqlServer(
                            connectionString,
                            sqlServerOptionsBuilder =>
                            {
                                sqlServerOptionsBuilder
                                    .CommandTimeout((int)TimeSpan.FromMinutes(3).TotalSeconds)
                                    .EnableRetryOnFailure()
                                    .MigrationsAssembly(typeof(MsSqlServiceCollectionExtensions).Assembly.FullName);
                            })
                        .AddInterceptors(serviceProvider.GetRequiredService<SecondLevelCacheInterceptor>()));
            return services;
        }
    }

ABP Version: 4.3

إجابة

Sure. The same as in endpoint. CurrentUser is materizled from JWT token which passed to event data or in appsettings

public class UserStatBackgroundJob : IAsyncBackgroundJob<Object>
{
    private readonly IUserLookupService<AppUser> _userLookupService;
    
    ICurrentUser _currentUser;     <<--------

    public UserStatBackgroundJob(IUserLookupService<AppUser> userLookupService, ICurrentUser currentUser)
    {
        _userLookupService = userLookupService;
        _currentUser = currentUser      <<-------
    }

    public async Task ExecuteAsync(Object args)
    {
        long userCount = await _userLookupService.GetCountAsync();
        
        var userName = currentUser.Name;         <<---------

        //usage of userCount
    }
}
إجابة

Hi

Sorriy, but I could not find what you wrote about on page provided by link. Can you please send link to source of project you talking about?

Also I would want to give more details about by question. I would like to not bind to http client proxy implementation of application services, so calls will be done via HTTP always for any deployment: monolith or microservices. I want to keep event handlers without changes, but also implement Attribute for authentication and authorization, at same way as that done in middleware which is called before endpoint execution. This Attribute will use JWT token provided in app configuration. Execution authorization will be done before event handler call, in the way as it is done in ABP middleware before endpoint execution, so all application services in monolith will be called directly in runtime, as that would be done by another application service during endpoint execution.

In short - I want CurrentUser and CurrentTenant will be provided before event handler execution

إجابة

Hi @maliming

Can you please explain, how I can do authorization in event handler? I mean that I need to reach the same result as on endpoint execution. Before endpoint executed there is middleware doing authorization. I would like to make that in scope of event handlers

إجابة

Ok. I will close this question

إجابة

Please read carefully what I wrote above. My background job in module A needs to get some data from module B. For example - user amount. How can I move Identity module GetUserCount endpoint logic into domain service of module where background job is implemented?

إجابة

Sure. There is simple example of BackgroundJob in my module

public class UserStatBackgroundJob : IAsyncBackgroundJob<Object>
        {
            private readonly IUserLookupService<AppUser> _userLookupService;

            public UserStatBackgroundJob(IUserLookupService<AppUser> userLookupService)
            {
                _userLookupService = userLookupService;
            }

            public async Task ExecuteAsync(Object args)
            {
                long userCount = await _userLookupService.GetCountAsync();

                //usage of userCount
            }
        }

Yes, I did that. I disbaled UoW via attribute and created UoW for each call of endpoints of other module

عرض 11 الي 20 من 46 إدخالات
Made with ❤️ on ABP v8.2.0-preview Updated on مارس 25, 2024, 15:11