Base solution for your next web application

Activities of "chrisk"

Question

Hi there !

I started using EventBus in application and I'm using my DomainServices in IEventHandler<T> implementations. Thing is that all methods in my DomainServices are async using TPL.

Since handlers are non async void and I don't want to try adding async keyword to signature since its considered as very bad practice, what would you normally do in that case ?

  • I create non async version of methods that I need?
  • Use AsyncHelper.RunSync() ? how robust this solution is?
  • Other approach ?

All comments will be appreciated :)

Hi There,

Are you using EF for data access ? If so there is generic repository that you propably want to use. How do you register your repositories ?

Thank you for response :)

It was confusing me for some time now - using TPL synchronously due to potential issues I could run into without broader knowledge of it.

Hi there,

I've got questions in regards to Token Authorization used in dynamic WebApi project. I'm able to successfully use WebApi and call authorized method once obtained token, however I don't know when and if token expires ? If so - how to check it ?

Thank you for all answers and suggestions.

Hi,

Thank you very much for response. Do you know where to look to customize it ? I'm quite new to Identity and Authorization features :P

Hi There,

When you publish notifications userIds[] is UserIdentifier[]. UserIdentifier is a type you should use, it holds user id and tenant id. There is extension method on user type ToUserIdentifier() that you can use for convenience.

Hi,

I really like idea Abp implementation of certain concepts like IMustHaveTenant. I'm trying to implement something similar. I have created IMustHaveSourceAccount interface and I want to implement logic that will always validate if entity that implements IMustHaveSourceAccount has SourceAccountId property set.

What I got so far is:

protected override void ApplyAbpConcepts() { //Apply our concepts first
ApplyOrdersConnectorConcepts();

        base.ApplyAbpConcepts();
    }

    protected virtual void ApplyOrdersConnectorConcepts()
    {
        var entries = ChangeTracker.Entries().ToList();
        foreach (var entry in entries)
        {
            switch (entry.State)
            {
                case EntityState.Added:
                    CheckMustHaveSourceAccountIdProperty(entry);
                    break;
            }
        }

    }

    protected virtual void CheckMustHaveSourceAccountIdProperty(object entityAsObj)
    {
        if (!(entityAsObj is IMustHaveSourceAccount))
        {
            return;
        }

        var entity = entityAsObj.As&lt;IMustHaveSourceAccount&gt;();
        if (entity.SourceAccountId == 0)
        {
            throw new AbpException("Can not set SourceAccountId to 0 for IMustHaveSourceAccount entities!");
        }
    }

My debugging indicates that there is problem when checking if entity is derived from IMustHaveSourceAccount. I got migrations code with seed data that is inserting few records including entities that derive from IMustHaveSourceAccount and deliberately set SourceAccountId = 0 which should throw exception.

Even when I changed method to throw exception if entity implements my interface nothing happens: protected virtual void CheckMustHaveSourceAccountIdProperty(object entityAsObj) { if (!(entityAsObj is IMustHaveSourceAccount)) { return; } throw new AbpException("Can not set SourceAccountId to 0 for IMustHaveSourceAccount entities!"); }

Throwing exception before If block works so my method is getting called. Do you know what I'm doing wrong?

Thank you

Hi,

I found where the problem was, which was very silly btw.

I was passing EntityEntry object instead of actual entity. CheckMustHaveSourceAccountIdProperty(entry);

Should be like this CheckMustHaveSourceAccountIdProperty(entry.Entity);

Hi,

I'm trying to execute some code as separate transaction inside UoW method. Basically I got IApplicationService which receives some order data and then selects appropriate workflow to execute. Workflows are created in a way so those can be easily turned into background job. but at the moment I'm executing them within my AppService method so there is already UoW applied right?

What I need to do now is to capture errors that are occurring and send email notification. I implemented email notifications using AbpNotifications. My problem is that I want to rollback all changes that were generated within workflow execution then publish notification and rethrow any errors from my workflow so those will be logged and displayed on UI.

Than you very much

Hi,

Thank you very much for response. I was considering solution that you proposed and but I'm not sure how I could get detailed information using this approach. I need to get bit more detailed information about errors occurring in my workflows as well as possibility to execute within IApplicationService or as BackgroundJob.

In the end I got it to work in following way :

  • Changed implementation of workflows to handle exceptions internally (previously workflow could throw exceptions and were handled in my IApplicationService but I had to made it possible to execute the same workflow as background job)

  • Changed return type of my "Execute(input)" public method of workflow from void to WorkflowExecutionResult (WorkflowExecutionResult is used to return whether execution was successful or not and errors are passed as list of ValidationResult so I can use those to throw AbpValidationException in my IApplicationService if I want to display errors to client)

  • Last thing was making Workflow.Execute method to execute as Separate UoW transaction, I used - [UnitOfWork(TransactionScopeOption.RequiresNew)]. Originally that caused me problems and was the reason to start this post. I think what I was doing wrong was that my workflow classes are not implementing shared interface thus are not called over interface and with old signature which was public void Execute() method wasn't intercepted. Changing signature to virtual did the job.

Does it sound like valid solution? I hope I'm not missing something and wont try to fight against framework.

Showing 1 to 10 of 17 entries