Mastering ABP Framework: Build maintainable .NET solutions by implementing software development best practices
()
About this ebook
ABP Framework is a complete infrastructure for creating modern web applications by following software development best practices and conventions. With ABP's high-level framework and ecosystem, you can implement the Don’t Repeat Yourself (DRY) principle and focus on your business code.
Written by the creator of ABP Framework, this book will help you to gain a complete understanding of the framework and modern web application development techniques. With step-by-step explanations of essential concepts and practical examples, you'll understand the requirements of a modern web solution and how ABP Framework makes it enjoyable to develop your own solutions. You'll discover the common requirements of enterprise web application development and explore the infrastructure provided by ABP. Throughout the book, you’ll get to grips with software development best practices for building maintainable and modular web solutions.
By the end of this book, you'll be able to create a complete web solution that is easy to develop, maintain, and test.
Related to Mastering ABP Framework
Related ebooks
Hands-on Application Development using Spring Boot: Building Modern Cloud Native Applications by Learning RESTFul API, Microservices, CRUD Operations, Unit Testing, and Deployment Rating: 5 out of 5 stars5/5ASP.NET Core 6 and Angular: Full-stack web development with ASP.NET 6 and Angular 13 Rating: 0 out of 5 stars0 ratingsASP.NET Core 5 and Angular: Full-stack web development with .NET 5 and Angular 11 Rating: 0 out of 5 stars0 ratingsASP.NET Core for Jobseekers: Build Career in Designing Cross-Platform Web Applications Using Razor and Entity Framework Core Rating: 0 out of 5 stars0 ratingsImplementing C# 11 and .NET 7.0: Learn how to build cross-platform apps with .NET Core (English Edition) Rating: 0 out of 5 stars0 ratingsMastering NetBeans Rating: 0 out of 5 stars0 ratingsASP.NET Core 8 and Angular: Full-stack web development with ASP.NET Core 8 and Angular Rating: 0 out of 5 stars0 ratingsMastering Backbone.js Rating: 0 out of 5 stars0 ratingsLearning Underscore.js Rating: 0 out of 5 stars0 ratingsBlazor WebAssembly by Example: A project-based guide to building web apps with .NET, Blazor WebAssembly, and C# Rating: 0 out of 5 stars0 ratingsMastering Visual Studio 2017 Rating: 0 out of 5 stars0 ratingsASP.NET Core Essentials Rating: 0 out of 5 stars0 ratingsBuilding SOA-Based Composite Applications Using NetBeans IDE 6 Rating: 0 out of 5 stars0 ratingsSolution Architecture with .NET: Learn solution architecture principles and design techniques to build modern .NET solutions Rating: 0 out of 5 stars0 ratingsSoftware Architecture for Busy Developers: Talk and act like a software architect in one weekend Rating: 0 out of 5 stars0 ratingsASP.NET and VB.NET in 30 Days: Acquire a Solid Foundation in the Fundamentals of Windows and Web Application Development Rating: 0 out of 5 stars0 ratingsMastering Spring 5.0 Rating: 5 out of 5 stars5/5ASP.NET Core and Vue.js: Build real-world, scalable, full-stack applications using Vue.js 3, TypeScript, .NET 5, and Azure Rating: 0 out of 5 stars0 ratingsMobile Development with .NET: Build cross-platform mobile applications with Xamarin.Forms 5 and ASP.NET Core 5 Rating: 0 out of 5 stars0 ratingsHands-On High Performance with Spring 5: Techniques for scaling and optimizing Spring and Spring Boot applications Rating: 0 out of 5 stars0 ratingsFull Stack Development with Spring Boot and React: Build modern and scalable web applications using the power of Java and React Rating: 0 out of 5 stars0 ratingsAngular 6 for Enterprise-Ready Web Applications: Deliver production-ready and cloud-scale Angular web apps Rating: 4 out of 5 stars4/5React Application Architecture for Production: Learn best practices and expert tips to deliver enterprise-ready React web apps Rating: 0 out of 5 stars0 ratingsJava 11 and 12 – New Features: Learn about Project Amber and the latest developments in the Java language and platform Rating: 0 out of 5 stars0 ratingsPractical Ansible: Learn how to automate infrastructure, manage configuration, and deploy applications Rating: 0 out of 5 stars0 ratings
Programming For You
Excel : The Ultimate Comprehensive Step-By-Step Guide to the Basics of Excel Programming: 1 Rating: 5 out of 5 stars5/5Coding All-in-One For Dummies Rating: 4 out of 5 stars4/5Python Programming : How to Code Python Fast In Just 24 Hours With 7 Simple Steps Rating: 4 out of 5 stars4/5Python: Learn Python in 24 Hours Rating: 4 out of 5 stars4/5SQL QuickStart Guide: The Simplified Beginner's Guide to Managing, Analyzing, and Manipulating Data With SQL Rating: 4 out of 5 stars4/5Learn Python in 10 Minutes Rating: 4 out of 5 stars4/5PYTHON: Practical Python Programming For Beginners & Experts With Hands-on Project Rating: 5 out of 5 stars5/5Excel 101: A Beginner's & Intermediate's Guide for Mastering the Quintessence of Microsoft Excel (2010-2019 & 365) in no time! Rating: 0 out of 5 stars0 ratingsHTML in 30 Pages Rating: 5 out of 5 stars5/5Python: For Beginners A Crash Course Guide To Learn Python in 1 Week Rating: 4 out of 5 stars4/5Learn Python by Coding Video Games (Beginner): Learn Python by Coding Video Games Rating: 2 out of 5 stars2/5Problem Solving in C and Python: Programming Exercises and Solutions, Part 1 Rating: 5 out of 5 stars5/5Tiny Python Projects: Learn coding and testing with puzzles and games Rating: 4 out of 5 stars4/5Nostalgia and Videogame Music: A Primer of Case Studies, Theories, and Analyses for the Player-Academic Rating: 0 out of 5 stars0 ratingsHow To Become A Data Scientist With ChatGPT: A Beginner's Guide to ChatGPT-Assisted Programming Rating: 4 out of 5 stars4/5The 1 Page Python Book Rating: 2 out of 5 stars2/5Linux: Learn in 24 Hours Rating: 5 out of 5 stars5/5SQL All-in-One For Dummies Rating: 3 out of 5 stars3/5Grokking Algorithms: An illustrated guide for programmers and other curious people Rating: 4 out of 5 stars4/5Learn to Code. Get a Job. The Ultimate Guide to Learning and Getting Hired as a Developer. Rating: 5 out of 5 stars5/5The Tetris Effect: The Cold War Battle for the World's Most Addictive Game Rating: 3 out of 5 stars3/5
Reviews for Mastering ABP Framework
0 ratings0 reviews
Book preview
Mastering ABP Framework - Halil İbrahim Kalkan
ABP IS AN IMPRINT OF PACKT PUBLISHING
Mastering ABP Framework
Copyright © 2022 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the authors, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
Group Product Manager: Pavan Ramchandani
Publishing Product Manager: Aaron Tanna
Senior Editor: Hayden Edwards
Content Development Editor: Rashi Dubey
Technical Editor: Simran Udasi
Copy Editor: Safis Editing
Project Coordinator: Rashika Ba
Proofreader: Safis Editing
Indexer: Tejal Daruwale Soni
Production Designer: Alishon Mendonca
Marketing Coordinator: Anamika Singh
First published: January 2022
Production reference: 1280122
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham
B3 2PB, UK.
ISBN 978-1-80107-924-2
www.packt.com
To my wife, Gözde, for always trusting me and being with me, and to my kids, Tuana and Mete.
– Halil İbrahim Kalkan
Foreword
I have known Halil İbrahim Kalkan for almost 20 years and we have been working together for more than 10 years. Halil is one of the greatest developers/software architects I have ever worked with. He likes solving common software problems and tries to create solutions that other developers can use. With this passion, he created ASP.NET Boilerplate Framework back in 2013 and then included me in his journey of framework development. After ASP.NET Boilerplate became very popular in the .NET world, Halil decided to re-write it with the name ABP Framework. ABP Framework is a complete infrastructure for creating modern web applications by following software development best practices and conventions.
In this book, Halil will show you how easy it is to build robust, maintainable, and scalable software solutions using ABP Framework. Developing modular software is every developer's dream, but it is really hard to do. Halil will also show you how to create modular software easily using ABP Framework.
You will also learn how to work with Entity Framework Core and MongoDB to develop the data access layer for your application, how to build UIs with ASP.NET Core MVC (Razor Pages) and Blazor, and how ABP Framework seamlessly supports multi-tenancy.
To develop robust software, testing the application is very important. Halil will guide you on how to write unit and integration tests using ABP Framework easily.
By the end of this book, you will be able to create a complete web solution that is easy to develop, maintain, and test.
İsmail ÇAĞDAŞ
Co-Founder – Volosoft
Contributors
About the author
Halil İbrahim Kalkan is a computer engineer who loves building reusable libraries, creating distributed solutions, and working on software architectures. He is an expert in domain-driven design, multi-tenancy, modularity, and microservice architecture. Halil has been building software since 1997 (when he was 14) and working as a professional since 2007. He has a lot of articles and talks on software development. He is a very active open source contributor and has built many projects based on web and Microsoft technologies. Halil is currently leading the open source ABP Framework, which provides a complete architectural solution for building .NET applications.
I want to thank the people who were close to me and supported me while writing this book, especially my wife, Gözde, for her understanding and patience with me spending my all weekends completing this book, and my mother, Fatma, for always supporting me. I also thank Aaron Tanna, who came to me with this book offer; Hayden Edwards, Rashi Dubey, and Lee Richardson, for their excellent reviews and editorial support; and Berkan Şaşmaz, Engincan Veske, Armağan Ünlü, Melis Platin, and Enis Necipoğlu, for their help in preparing the EventHub reference application. This book could not have existed without your help.
About the reviewer
Lee Richardson is a Microsoft MVP and a prolific writer, speaker, and YouTuber on .NET and open source topics. He frequently covers ABP content on his popular Code Hour
YouTube channel, his blog, and on CodeProject. Throughout his two decades of software development consulting in the Washington DC area, he has spoken scores of times at code camps, conferences, and user groups. He currently works as a Solution Samurai at InfernoRed Technologies. He is active on Twitter, where you can reach him @lprichar.
Table of Contents
Preface
Part 1: Introduction
Chapter 1: Modern Software Development and ABP Framework
Challenges of developing an enterprise web solution
Setting up the architecture
Don't repeat yourself!
Building a UI base
Implementing common business requirements
Understanding what ABP Framework offers
The ABP architecture
The startup templates
The ABP infrastructure
The community
Summary
Chapter 2: Getting Started with ABP Framework
Technical requirements
IDE/Editor
.NET 6 SDK
Database management system
Installing the ABP CLI
Creating a new solution
Downloading the startup solution
Using the ABP CLI
Running the solution
The connection string
Creating a database
Running the web application
Exploring the pre-built modules
Account module
Identity module
Tenant Management module
Summary
Chapter 3: Step-By-Step Application Development
Technical requirements
Creating the solution
Defining the domain objects
Category
ProductStockState
Product
Constants
EF Core and database mappings
Adding entities to the DbContext class
Mapping entities to the database tables
The Add-Migration command
Seeding data
Migrating the database
Listing the product data
The ProductDto class
IProductAppService
ProductAppService
Object to object mapping
Testing the ProductAppService class
Auto API Controllers and the Swagger UI
Dynamic JavaScript proxies
Creating a products page
Adding a new menu item
Creating the products data table
Creating products
Application service contracts
Application service implementation
UI
Editing products
Application service contracts
Application service implementation
UI
Deleting products
Summary
Chapter 4: Understanding the Reference Solution
Technical requirements
Introducing the application
Understanding the architecture
Authentication flow
Exploring the solution
Project dependencies
Running the solution
Cloning the GitHub repository
Running the infrastructure
Opening the solution
Creating a database
Running the applications
Using the Tye project
Summary
Part 2: Fundamentals of ABP Framework
Chapter 5: Exploring the ASP.NET Core and ABP Infrastructure
Technical requirements
Understanding modularity
The Startup class
Defining a module class
Module dependencies and the startup module
Module lifecycle methods
Using the dependency injection system
Service lifetime
Conventional service registrations
Dependency interfaces
The Dependency attribute
Exposing services
Configuring an application
Setting the configuration values
Reading the configuration values
Implementing the options pattern
Defining an options class
Configuring the options
Using the configured option values
Setting the options via the configuration
ASP.NET Core and ABP options
Logging
Summary
Chapter 6: Working with the Data Access Infrastructure
Technical requirements
Defining entities
AggregateRoot classes
Entity classes
Entities with CPKs
The GUID PK
Working with repositories
Generic repositories
Custom repositories
EF Core integration
Configuring the DBMS
Defining DbContext
Registering DbContext with DI
Configuring entity mappings
Implementing custom repositories
Loading related data
MongoDB integration
Defining DbContexts
Configuring object mappings
Registering DbContext with DI
Implementing custom repositories
Understanding the UoW system
Configuring UoW options
Manually controlling the UoW
Summary
Chapter 7: Exploring Cross-Cutting Concerns
Technical requirements
Working with authorization and permission systems
Simple authorization
Using the permission system
Policy-based authorization
Authorizations outside of controllers
Validating user inputs
Using data annotation attributes
Custom validation with the IValidatableObject interface
Understanding the validation exception
Disabling the validation
Validation in other types
Integrating the FluentValidation library
Exception handling
User-friendly exceptions
Business exceptions
Controlling exception logging
Controlling the HTTP status code
Summary
Chapter 8: Using the Features and Services of ABP
Technical requirements
Obtaining the current user
Defining custom claims
Using the data filtering system
The soft-delete data filter
The multi-tenancy data filter
Disabling a data filter
Defining custom data filters
Controlling the audit logging system
Audit log object
Audit log scope
Auditing options
Disabling and enabling audit logging in detail
Caching data
Using the IDistributedCache
Configuring cache options
Error handling
Using the cache in a multi-tenancy application
Using Redis as the distributed cache provider
Invalidating cache values
Localizing the user interface
Configuring supported languages
Determining the current language
Defining a localization resource
Working with the localization JSON files
Getting localized texts
Configuring localization resources
Localizing in special services
Using localization on the client side
Summary
Part 3: Implementing Domain–Driven Design
Chapter 9: Understanding Domain-Driven Design
Technical requirements
Introducing DDD
What is domain-driven design?
DDD layers
Building blocks
Structuring a .NET solution based on DDD
Creating a simple DDD-based .NET solution
Evolution of the ABP startup solution
Separating the hosting from the UI
Dealing with multiple applications
Understanding the execution flow
Understanding the common principles
Database provider independence
Presentation technology-agnostic
Summary
Chapter 10: DDD – The Domain Layer
Technical requirements
Exploring the example domain
Designing aggregates and entities
What is an aggregate root?
Referencing other aggregates by their ID
Keep aggregates small
Determining the primary keys for entities
Implementing entity constructors
Using services to create aggregates
Implementing business logic and constraints
Using external services in entity methods
Implementing domain services
Implementing repositories
Building specifications
Parameterless specifications
Parameterized specifications
Combining specifications
Publishing domain events
Using the local event bus
Using the distributed event bus
Summary
Chapter 11: DDD – The Application Layer
Technical requirements
Implementing application services
Designing DTOs
Designing DTO classes
Validating input DTOs
Object-to-object mapping
DTO design best practices
Understanding the responsibilities of the layers
Authorizing users
Controlling the transaction
Validating the user input
Working with the current user
Summary
Part 4: User Interface and API Development
Chapter 12: Working with MVC/Razor Pages
Technical requirements
Understanding the theming system
The base libraries
The layouts
Using the bundling and minification system
Installing NPM packages
Using the standard packages
Importing script and style files
Creating page bundles
Configuring global bundles
Creating named bundles
Controlling the bundling and minification behavior
Working with menus
Working with Bootstrap tag helpers
Creating forms and implementing validation
Rendering form elements
Validating user inputs
Localizing forms
Implementing AJAX forms
Working with modals
Understanding the basics of modals
Working with forms inside modals
Adding JavaScript for modals
Using the JavaScript API
Accessing the current user
Checking user permissions
Checking the tenant features
Localizing strings
Showing message boxes
Showing notifications
Consuming HTTP APIs
Using the abp.ajax API
Using dynamic client proxies
Using static client proxies
Summary
Chapter 13: Working with the Blazor WebAssembly UI
Technical requirements
What is Blazor?
Getting started with the ABP Blazor UI
Authenticating the user
Understanding the theming system
Working with menus
Using the basic services
Authorizing the users
Localizing the user interface
Accessing the current user
Using the UI services
Showing message boxes
Showing notifications
Showing alerts
Consuming HTTP APIs
Working with global scripts and styles
Summary
Chapter 14: Building HTTP APIs and Real-Time Services
Technical requirements
Building HTTP APIs
Creating an HTTP API project
Creating ASP.NET Core controllers
Understanding the Auto API Controllers
Consuming HTTP APIs
Using ABP's dynamic client-side proxies
Using ABP's static (generated) client proxies
Using SignalR with ABP Framework
Using the ABP SignalR integration package
Configuring SignalR clients
Summary
Part 5: Miscellaneous
Chapter 15: Working with Modularity
Technical requirements
Understanding modularity
Class libraries and NuGet packages
Application modules
Building the Payment module
Creating a new application module
Restructuring the Payment module solution
Understanding the payment process
Providing configuration options
Installing the Payment module into EventHub
Setting the project dependencies
Configuring the database integration
Summary
Chapter 16: Implementing Multi-Tenancy
Technical requirements
Understanding multi-tenancy
What is SaaS?
What is multi-tenancy?
The database architecture
Working with the ABP multi-tenancy infrastructure
Enabling and disabling multi-tenancy
Determining the current tenant
Working with the current tenant
Switching between tenants
Disabling the data isolation
Designing the domain as multi-tenant
Using the feature system
Defining the features
Checking for the features
Managing tenant features
When to use multi-tenancy
Summary
Chapter 17: Building Automated Tests
Technical requirements
Understanding the ABP test infrastructure
Exploring the test projects
Exploring the test libraries
Running the tests
Building unit tests
Testing static classes
Testing classes with no dependencies
Testing classes with dependencies
Building integration tests
Understanding ABP integration
Mocking the database
Seeding the test data
Testing repositories
Testing domain services
Testing application services
Summary
Why subscribe?
Other Books You May Enjoy
Preface
ABP Framework is a complete infrastructure for creating modern web applications by following software development best practices and conventions. ABP provides a high-level framework and ecosystem to help you implement the Don’t Repeat Yourself (DRY) principle and focus on your business code.
Written by the creator of ABP Framework, this book will help you to gain a complete understanding of ABP Framework and modern web application development techniques from scratch. With step-by-step explanations of essential concepts and practical examples, you’ll understand the requirements of a modern web solution and how ABP Framework makes it enjoyable to develop your own solution. You’ll discover the common requirements of enterprise web application development and explore the infrastructure provided by ABP Framework. Throughout the book, you’ll get to grips with software development best practices for building maintainable and modular web solutions.
By the end of this book, you’ll be able to create a complete web solution that is easy to develop, maintain, and test.
Who this book is for
This book is for web developers who want to learn software architecture and best practices to build maintainable web-based solutions using Microsoft technologies and ABP Framework. Basic knowledge of C# and ASP.NET Core is necessary to get started with this book.
What this book covers
Chapter 1, Modern Software Development and ABP Framework, discusses the common challenges of developing a business application and explains how ABP addresses these challenges.
Chapter 2, Getting Started with ABP Framework, explains how you can create and run a new solution with ABP Framework.
Chapter 3, Step-By-Step Application Development, is the longest chapter of the book and shows application development with ABP Framework with an extensive example application. It is the main chapter for putting everything together. After this chapter, you may not understand all the ABP features but will be able to create your own application with the fundamental ABP concepts. You will understand the big picture here. Then, you will fill in the gaps and learn about all the details in the next chapters.
Chapter 4, Understanding the Reference Solution, explains the architecture and structure of the reference solution, EventHub, that was created as a large example application for the readers of this book. It is suggested that you read this chapter and make the solution work in your environment.
Chapter 5, Exploring the ASP.NET Core and ABP Infrastructure, explains some fundamental concepts such as dependency injection, basic modularity, configuration, and logging. These topics are essential to understanding development with ABP and ASP.NET Core.
Chapter 6, Working with the Data Access Infrastructure, introduces the entity, repository, and unit of work concepts, and shows how to work with Entity Framework Core and MongoDB. You will learn different ways of querying and manipulating data and controlling database transactions.
Chapter 7, Exploring Cross-Cutting Concerns, focuses on three important concerns you will need in your application: authorization, validation, and exception handling. These concerns are implemented in every part of your application. You will learn how to define and use a permission-based authorization system, validate user inputs, and deal with exceptions and exception messages.
Chapter 8, Using the Features and Services of ABP, covers some of the commonly used ABP features such as working with the current user, using the data filtering and audit log systems, caching data, and localizing the user interface.
Chapter 9, Understanding Domain-Driven Design, is the first part of the DDD-related chapters. It starts by defining DDD and structuring a .NET solution based on DDD. You will learn how ABP’s startup template has been evolved from DDD’s standard four-layered solution model. You will also learn about the building blocks and principles of DDD.
Chapter 10, DDD – The Domain Layer, continues looking at DDD with the domain layer. It begins by explaining the EventHub domain objects, since the examples in this chapter and the next chapter will be based on these objects. You will learn how to design aggregates; implement domain services, repositories, and specifications; and use an event bus to publish domain events.
Chapter 11, DDD – The Application Layer, focuses on the application layer. You will learn the best practices for designing and validating data transfer objects and implementing your application services. You will also find discussions and examples in this chapter to help you understand the responsibilities of the domain and application layers.
Chapter 12, Working with MVC/Razor Pages, covers developing MVC (Razor Pages) applications that generate the HTML on the server side. You will learn about ABP’s theming approach and learn about fundamental aspects such as bundling and minification, tag helpers, forms, menus, and modals. You will also learn how to make client-to-server API calls and use the JavaScript utility APIs provided by ABP Framework to show notifications, message boxes, and more.
Chapter 13, Working with the Blazor WebAssembly UI, is similar to the previous chapter and explains UI development with Microsoft’s new Blazor SPA framework and ABP Framework. Blazor is a great framework for developers to use their existing .NET skills in the browser. ABP takes things a few steps further by providing built-in solutions for consuming HTTP APIs, implementing theming, and providing utility services to make common UI tasks easier.
Chapter 14, Building HTTP APIs and Real-Time Services, explains how to create API controllers with the classic ASP.NET approach and ABP’s auto API controller system, and it discusses when you need to define controllers manually. In this chapter, you will also learn about dynamic and static C# proxies to automate client-to-server API calls from your .NET clients to your ABP-based HTTP services. This chapter also covers using SignalR with ABP Framework.
Chapter 15, Working with Modularity, explains reusable application module development with an example case. We’ll create a payment module for the EventHub solution and explain the structure of that module in this chapter. In this way, you will understand how to develop reusable modules and install them in an application.
Chapter 16, Implementing Multi-Tenancy, focuses on another fundamental ABP architecture, multi-tenancy, which is an architectural pattern to build Software-as-a-Service (SaaS) solutions. You will see whether multi-tenancy is the right architecture for your solution and learn how to develop your code to be compatible with ABP’s multi-tenancy system. This chapter also covers ABP’s features system, which is used to define application functionalities as features and assign them to tenants in a multi-tenant solution.
Chapter 17, Building Automated Tests, explains ABP’s test infrastructure and how to build unit and integration tests for your applications using xUnit as the test framework. You will also learn the basics of automated tests, such as assertions, mocking and replacing services, and dealing with exceptions.
To get the most out of this book
Basic knowledge of C# and ASP.NET Core is necessary to get started with this book.
If you are using the digital version of this book, we advise you to type the code yourself or access the code from the book’s GitHub repository (a link is available in the next section). Doing so will help you avoid any potential errors related to the copying and pasting of code.
Download the example code files
You can download the example code files for this book from GitHub at https://github.com/PacktPublishing/Mastering-ABP-Framework. If there’s an update to the code, it will be updated in the GitHub repository.
We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!
Download the color images
We also provide a PDF file that has color images of the screenshots and diagrams used in this book. You can download it here: https://static.packt-cdn.com/downloads/9781801079242_ColorImages.pdf
Conventions used
There are a number of text conventions used throughout this book.
Code in text: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: If you want to specify the database connection string, you can also pass the --connection-string parameter as shown in the following example:
A block of code is set as follows:
ConnectionStrings
: {
Default
: Server=(LocalDb)\\MSSQLLocalDB;Database=ProductManagement;Trusted_Connection=True
}
Any command-line input or output is written as follows:
dotnet tool install -g Volo.Abp.Cli
Bold: Indicates a new term, an important word, or words that you see onscreen. For instance, words in menus or dialog boxes appear in bold. Here is an example: ABP Framework provides a pre-built Application Startup Template.
Tips or Important Notes
Appear like this.
Get in touch
Feedback from our readers is always welcome.
General feedback: If you have questions about any aspect of this book, email us at [email protected] and mention the book title in the subject of your message.
Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packtpub.com/support/errata and fill in the form.
Piracy: If you come across any illegal copies of our works in any form on the internet, we would be grateful if you would provide us with the location address or website name. Please contact us at [email protected] with a link to the material.
If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.
Part 1: Introduction
The first part of this book introduces the challenges of modern web application development and explains how ABP solves the problems. It also shows how to create a new solution with ABP Framework and build a fully working, production-ready page to manage an entity. Finally, it explores the EventHub project, a real-world reference solution built with ABP Framework.
In this part, we include the following chapters:
Chapter 1, Modern Software Development and ABP Framework
Chapter 2, Getting Started with ABP Framework
Chapter 3, Step-by-Step Application Development
Chapter 4, Understanding the Reference Solution
Chapter 1: Modern Software Development and ABP Framework
Building software systems has always been complicated. Especially in these modern times, there are many challenges while creating even a basic business solution. You often find yourself implementing standard non-business requirements and digging into infrastructure problems rather than implementing your business code, which is the actual valuable part of the system you are trying to build.
ABP Framework helps you focus on the code that adds value to the stakeholders by offering a robust software architecture, automating the repetitive details, and providing the necessary infrastructure to help build modern web solutions. It provides an end-to-end, consistent development experience and improves your productivity. ABP gets you and your team up to speed with all the modern software development best practices pre-applied.
This book is the ultimate guide to developing web applications and systems using ABP Framework by following modern software development approaches and best practices.
This first chapter introduces the challenges of building a well-architected enterprise solution and explains how ABP Framework addresses these challenges. I will also explain the purpose and the structure of this book.
In this chapter, we will cover the following topics:
Challenges of developing an enterprise web solution
Understanding what ABP Framework offers
Challenges of developing an enterprise web solution
Before digging into ABP Framework, I want to present the challenges of developing a modern enterprise web solution to understand why we need an application framework like ABP Framework. Let's begin with the big picture: architecture.
Setting up the architecture
Before you start to write your code, you need to create a foundation for your solution. This is one of the most challenging phases of building a software system. You have a lot of options and need to make some fundamental decisions. Any decision you make at this stage will likely affect your application for the rest of its lifetime.
There are some common, well-known, system-level architectural patterns, such as monolithic architecture, modular architecture, and microservice architecture. Applying one of these architectures determines how you develop, deploy, and scale your solution and should be decided based on your requirements.
In addition to these system-level patterns, software development models such as Command and Query Responsibility Segregation (CQRS), Domain-Driven Design (DDD), Layered Architecture, and Clean Architecture determine how your code base is shaped.
Once you decide on your architecture, you should create the fundamental solution structure to start development with that architecture. In this phase, you also need to decide which language, framework, tools, and libraries you will use.
All these decisions need significant experience, so they are ideally done by experienced software architects and developers. However, not all the team members will have the same experience and knowledge level. You need to train them and determine the correct coding standards.
After setting up your architecture and preparing the fundamental solution, your team can start the development process. The next section discusses the common aspects that are repeated by every software solution and how you can avoid repeating them in your development.
Don't repeat yourself!
Don't Repeat Yourself (DRY) is a key principle for software development. Computers automate the repetitive tasks of the real world to make people's lives easier. So, why do we repeat ourselves while building software solutions?
Authentication is a very common concern of every software solution – single sign-on, Active Directory integration, token-based authentication, social logins, two-factor authentication, forgot/reset password, email activation, and more. Are most of these requirements are familiar to you? You are not alone! Almost all software projects have more or less similar requirements for authentication. Instead of building all these from scratch, using an existing solution, such as a library or a cloud service, is better. Such pre-built solutions are mature and battle-tested, which is important for security.
Some non-functional requirements, such as exception handling, validation, authorization, caching, audit logging, and database transaction management, are other sources of code repetition. These concerns are called cross-cutting concerns and should be handled in every web request. In a well-architected software solution, these concerns should be handled automatically by conventions in a central place in your code base, or you should have services to make them easier to implement.
When you integrate to third-party systems, such as RabbitMQ and Redis, you typically want to create abstractions and wrappers around the code that interact with these systems. In this way, your business logic is isolated from these infrastructure components. Also, you don't repeat the same connection, retry, exception handling, and logging logic everywhere in your solution.
Having a pre-built infrastructure to automate this repetitive work saves your development time so that you can focus on your business logic. The next section discusses another topic that takes up our time in every business application – the user interface.
Building a UI base
One of the fundamental aspects of an application is its user interface (UI). An application with an unfashionable and unusable UI would not be as attractive at first glance, even if it has outstanding business value under the hood.
While UI features and requirements vary for every application, some fundamental structures are common. Most applications need basic elements, such as alerts, buttons, cards, form elements, tabs, and data tables. You can use HTML/CSS frameworks such as Bootstrap, Bulma, and Ant Design instead of creating a design system for every application.
Almost every web application has a responsive layout with the main menu, toolbar, header, and footer with custom colors and branding. You will need to determine all these and implement a base UI kit for your application's pages and components. In this way, UI developers can create a consistent UI without dealing with the common structures.
Up to here, I've introduced some common infrastructure requirements, mostly independent from any business application. The next section discusses common business requirements for most enterprise systems.
Implementing common business requirements
While every application and system is unique and their value comes from that uniqueness, every enterprise system has some fundamental supporting requirements.
A permission-based authorization system is one of these fundamental requirements. It is used to control the privileges of users and clients of the application. If you want to implement this yourself, you should create an end-to-end solution with database tables, authorization logic, permission caches, APIs, and UI pages to assign these permissions to your users and check them when needed. However, such a system is pretty generic and can be developed as a shared identity management functionality (a reusable module) and used by multiple applications.
Like identity management, many systems need functionalities such as audit log reporting, tenant and subscription management (for SaaS applications), language management, file uploading and sharing, multi-language management, and time zone management. In addition to the pre-built application functionalities (modules), there may be low-level requirements, such as implementing the soft-delete pattern and storing Binary Large Object (BLOB) data in your applications.
All these common requirements can be built from scratch, which can be the only solution for some enterprise systems. However, if these functionalities are not the main value that's provided by your application, you can consider using pre-built modules and libraries where they are available and customize them based on your requirements.
In the next section, you will learn how ABP Framework helps us with the common infrastructure and base requirements that were discussed in this section.
Understanding what ABP Framework offers
ABP Framework offers an opinionated architecture to help you build enterprise software solutions with best practices on top of the .NET and ASP.NET Core platforms. It provides the fundamental infrastructure, production-ready modules, themes, tooling, guides, and documentation to implement that architecture properly and automate the details and repetitive work as much as possible.
In the next few sub-sections, I will explain how ABP does all these, starting with the architecture.
The ABP architecture
I mentioned that ABP offers an opinionated architecture. In other words, it is an opinionated framework. So, I should first explain what an unopinionated framework is and what an opinionated framework is.
As I stated in the Setting up the architecture section, preparing a foundation for a software solution requires a lot of decisions; you should decide on the system architecture, development model, techniques, patterns, tools, and libraries to use in your solution.
Unopinionated frameworks, such as ASP.NET Core, don't say much about these decisions and mostly leave it up to you. For example, you can create a layered solution by separating your UI layer from the data access layer, or you can create a single-layered solution by directly accessing the database from your UI pages/views. You can use any library, so long as it is compatible with ASP.NET Core, and you can apply any architectural pattern. Being unopinionated makes ASP.NET Core flexible and usable in different scenarios. However, it assigns the responsibility to you to make all these decisions, set up the right architecture, and prepare your infrastructure to implement that architecture.
I don't mean ASP.NET Core has no opinion at all. It assumes you are building a web application or API based on the HTTP specification. It clearly defines how your UI and API layers should be developed. It also offers some low-level infrastructure components such as dependency injection, caching, and logging (in fact, these components are usable in any .NET application and not specific to ASP.NET Core, but they are mainly developed alongside ASP.NET Core). However, it doesn't say much about how your business code is shaped and which architectural patterns you will use.
ABP Framework, on the other hand, is an opinionated framework. It believes that certain ways of approaching