Open Closed

Checks and exception types in entities created by Abp Suite #5826


User avatar
0
ademaygun created
  • ABP Framework version: v7.3.2
  • UI Type: Angular
  • Database System: EF Core
  • Tiered (for MVC) or Auth Server Separated (for Angular): no
  • Exception message and full stack trace:
  • Steps to reproduce the issue:

When I create an entity with Abp Suite, I notice that some length and not-null checks are being performed.

  1. Why is BusinessException not being thrown in checks made with the Check class, and instead ArgumentException/ArgumentNull exceptions are thrown? (I don't see any drawback to throwing a business exception in the domain layer)
  2. The relevant checks are being performed in the constructor, but the properties have accessible set accessors. There is also a gap here.

If you agree with what I've mentioned in both points, Abp Suite should generate more robust code and I expect a change in this regard.


3 Answer(s)
  • User Avatar
    0
    Anjali_Musmade created
    Support Team Support Team Member

    Hello ademaygun,

    Thanks for your suggestions will look into it.

    you may refer this https://support.abp.io/QA/Questions/2092/How-should-we-customize-exception-message-of-CheckNotNull--class-for-specific-cases to customize exception messages.

    Please do let me know if found helpful

    Thank you, Anjali

  • User Avatar
    0
    ademaygun created

    Hello Anjali_Musmade,

    Thank you for your response. It was definitely helpful to see this question. However, if possible, resolving the issue at its source is always a better solution. I'm curious about the following:

    Would using ArgumentException instead of BusinessException in the Check class called within the Entity be a preference or a necessity? Because before .NET 7, we couldn't perform dependency injection into entity classes. Therefore, was it a necessity to use exceptions of type ArgumentException in entity classes due to the inability to localize them, or was it a deliberate choice?

    About 10 months ago, Halil İbrahim Kalkan published an impressive article. I would like to see the adaptation of the Abp Suite's entity and manager classes in accordance with this article.

  • User Avatar
    0
    Anjali_Musmade created
    Support Team Support Team Member

    Hello ademaygun,

    Please have look to this https://docs.abp.io/en/abp/latest/Exception-Handling#business-exceptions

    I think business exception are something user can define on there own, so that's why it is not predefined For example you can see how asp.net is also throwing argumentnull exception in there domain class https://github.com/aspnet/AspNetIdentity/blob/main/src/Microsoft.AspNet.Identity.Core/UserManager.cs#L435

    if you want the entity to generate BusinessException when you are creating entity from abp suite you can customize the template

    See below link https://docs.abp.io/en/commercial/latest/abp-suite/editing-templates

    please do let me know if found helpful

    Thank you, Anjali

Made with ❤️ on ABP v8.2.0-preview Updated on March 25, 2024, 15:11