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 99 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 95 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 87 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 80 weeks ago
nice info
steavejames9@gmail.com 64 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 42 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 42 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 42 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!
lovelylula 32 weeks ago
Intuitive and smooth vehicle control, Drift Hunters helping you easily perform beautiful drifts.
Faska Gaster 16 weeks ago
https://community.abp.io/posts/reuse-abp-vnext-modules-to-quickly-implement-application-features-tdtmwd9w
Jacket Hunt 9 weeks ago
Wow, what an incredible read! Thank you for sharing this insightful post. It deeply resonated with me, and I gained so much valuable information from it.