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
- Install the NuGet package
EasyAbp.PrivateMessaging.Application
to theAddressBook.Application
project. - Install the NuGet package
EasyAbp.PrivateMessaging.Application.Contracts
to theAddressBook.Application.Contracts
project. - Install the NuGet package
EasyAbp.PrivateMessaging.Domain
to theAddressBook.Domain
project. - Install the NuGet package
EasyAbp.PrivateMessaging.Domain.Shared
to theAddressBook.Domain.Shared
project. - Install the NuGet package
EasyAbp.PrivateMessaging.EntityFrameworkCore
to theAddressBook.EntityFrameworkCore
project. - Install the NuGet package
EasyAbp.PrivateMessaging.HttpApi
into theAddressBook.HttpApi
project. - Install the NuGet package
EasyAbp.PrivateMessaging.HttpApi.Client
into theAddressBook.HttpApi.Client
project. - Install the NuGet package
EasyAbp.PrivateMessaging.Web
into theAddressBook.Web
project (you can skip this step if you do not need the UI).
Step 2: Add Module Dependencies and Configurations
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.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
Run the command
dotnet ef migrations add Installed_Pm_Module -s ../AddressBook.DbMigrator
in the directory of AddressBook.EntityFrameworkCore.DbMigrations project.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.
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:
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.
Comments
amandalawrancee@gmail.com 106 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 103 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.