Base solution for your next web application

Activities of "chrisk"

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<IMustHaveSourceAccount>();
        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 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,

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,

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.

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,

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 ?

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 :)

Showing 11 to 17 of 17 entries