Reuse ABP vNext Modules to Quickly Implement Application Features

In the previous article, we have completed the basic features of the address book application.

In this article, we will install the PrivateMessaging module to our address book application, so that users can send private messages to each other and get new message notifications on the website.

In the design of the private messaging module, users can send private messages to themselves, but we will override the design to prohibit users from sending private messages to themselves at the end of this article.

What Is a Module in ABP Framework?

Using the ABP framework, you can make some modules in advance, such as external login implementation, private messaging, file upload, blog, forum, and other modules, and package them for later use. When developing a specific application, you can easily install modules into your application, saving a lot of repetitive work.

In addition to making your own modules, you can also install modules maintained by the open-source community on NuGet. Of course, the community is also waiting for your contribution.

Install the Private Messaging Module

The module (EasyAbp.PrivateMessaging) we use is developed and maintained by the EasyAbp organization, and you can even use it for free in commercial applications.

Now we will start to install the module step by step.

Step 1: Install the Module's NuGet Packages

  1. Install the NuGet package EasyAbp.PrivateMessaging.Application to the AddressBook.Application project.
  2. Install the NuGet package EasyAbp.PrivateMessaging.Application.Contracts to the AddressBook.Application.Contracts project.
  3. Install the NuGet package EasyAbp.PrivateMessaging.Domain to the AddressBook.Domain project.
  4. Install the NuGet package EasyAbp.PrivateMessaging.Domain.Shared to the AddressBook.Domain.Shared project.
  5. Install the NuGet package EasyAbp.PrivateMessaging.EntityFrameworkCore to the AddressBook.EntityFrameworkCore project.
  6. Install the NuGet package EasyAbp.PrivateMessaging.HttpApi into the AddressBook.HttpApi project.
  7. Install the NuGet package EasyAbp.PrivateMessaging.HttpApi.Client into the AddressBook.HttpApi.Client project.
  8. Install the NuGet package EasyAbp.PrivateMessaging.Web into the AddressBook.Web project (you can skip this step if you do not need the UI).

Step 2: Add Module Dependencies and Configurations

  1. Add the dependency of the module to the module class of the above projects, for example, we add the attribute [DependsOn(PrivateMessagingApplicationModule)] to the class in the AddressBookApplicationModule.cs of the AddressBook.Application project, and so on.

  2. Find the OnModelCreating method in AddressBookMigrationsDbContext.cs of the AddressBook.EntityFrameworkCore.DbMigrations project and add the code builder.ConfigurePrivateMessaging(); to it to configure the EF Core migration of the module.

Step 3: Create EF Core Migration and Update the Database

  1. Run the command dotnet ef migrations add Installed_Pm_Module -s ../AddressBook.DbMigrator in the directory of AddressBook.EntityFrameworkCore.DbMigrations project.

  2. Run the AddressBook.DbMigrator project, it will automatically update the database.

If you want to learn more about this step, you can read the ABP official documentation.

Step 4: Run the Application

Now run the AddressBook.Web project, we can see that the private messaging module has been installed successfully.

HomePage

Improvement: Prohibit Users From Sending Private Messages to Themselves

The ABP framework allows us to override the code in the module. Please create a new file MyPrivateMessageAppService.cs in the AddressBook.Application project:

[Dependency(ReplaceServices = true)]
public class MyPrivateMessageAppService : PrivateMessageAppService
{
    // ctor

    public override Task<PrivateMessageDto> CreateAsync(CreateUpdatePrivateMessageDto input)
    {
        if (input.ToUserName == CurrentUser.UserName)
        {
            throw new UserFriendlyException("Don't send messages to yourself");
        }
        
        return base.CreateAsync(input);
    }
}

If a user sends a message to himself, he will see the error message:

SendToSelf

Thanks to the extensible modular design of the ABP framework, static files (such as JS and CSS files) and pages can be overridden. Please read the ABP official document for more information: Customizing the Existing Modules

Postscript

If you want to learn more about the private messaging module, please read its documentation.

By the way, the EasyAbp organization has many powerful and useful modules, such as EShop, PaymentService, GiftCardManagement, which can improve your development efficiency and enhance the reliability of applications. If you are interested, please read EasyAbp Guide to learn more.

I look forward to the launch of ABP's official module market (market.abp.io) in the future, providing community modules list, search, and automatic installation features, making it easier for us to install modules.

Next

In the next article, we will upgrade the address book application to a multi-tenant SaaS application with a minor change.

reusing-modules
amandalawrancee@gmail.com 64 weeks ago

The trick to writing a good essay is to know what to write about or check this article https://goodmenproject.com/learning/best-services-to-hire-an-essay-writer-in-2021/ . Your school-specific essay is a supplement to your general application and helps the school understand you better. This is a time for you to show the admissions committee why you are right for the school.

olja89malynovskaya@gmail.com 61 weeks ago

Truth be told, not every student is given to essay writing. And sometimes it is better to ask https://www.nursingpaper.com/our-services/nursing-essay-writing-service/ for help right away. It will save time and nerves. And at the same time it will bring a good grade.

markspencer943@gmail.com 53 weeks ago

Can I say it is such a relief to discover somebody who truly knows what theyre preaching online? You actually have learned to bring a problem to light and make it crucial. More people should see this and can see this side of the story. https://americasuits.com/love-on-tour-2022-harry-styles-tracksuit I cant believe youre no more well-known simply because you definitely contain the gift.

annacrawd@gmail.com 46 weeks ago

nice info

steavejames9@gmail.com 30 weeks ago

Whether you're strolling through a park, sipping on your favorite brew, or simply soaking in the stillness, today's all about you. You're the star of this stripped-back session, basking in the luxury of doing... well, not much at all. It's like hitting pause on the whirlwind of life, giving yourself permission to just be.

Sasha Rebels 8 weeks ago

Embark on a journey of precision in wellness as we decode the intricacies of determining the correct dosage for Retatrutide. Our comprehensive guide navigates through the science, considerations, and optimal dosing schedules, providing insights to help you achieve the full benefits of this innovative therapeutic approach.

Sasha Rebels 8 weeks ago

Embark on a journey of precision in wellness as we decode the intricacies of determining the correct dosage for Retatrutide. Our comprehensive guide navigates through the science, considerations, and optimal dosing schedules, providing insights to help you achieve the full benefits of this innovative therapeutic approach.

Boos Ter 8 weeks ago

Good afternoon friends ! I want to share my experience of playing on the platform . This is a place where every slots fan will find something to his liking. A large selection of games generous bonuses and constant updates - that's what makes this platform especially attractive. I myself am here all the time and I find something amazing every time!

Catherine Barrett 2 days ago

SlotsCity.com is a dynamic online gaming platform that caters to players seeking a high-quality and immersive casino experience. Featuring a diverse range of captivating slot games, this site ensures that every player can find their perfect match. The site's sleek and modern design enhances the overall user experience, making it easy to navigate and enjoy all that it has to offer. With exciting bonuses and promotions regularly available, players can maximize their gaming experience and increase their chances of winning big. Discover the excitement and thrill of SlotsCity.com today and embark on an unforgettable gaming journey like no other.

More from gdlcf88