Effortlessly kickstart your gRPC service development with a modern and robust boilerplate built on .NET 7. This project integrates essential tools and best practices to ensure scalability, maintainability, and ease of use for developers.
This project is a boilerplate for building gRPC-based services using .NET 7. It includes multiple components that work together to create a functional system for client-server communication via gRPC. Below is a breakdown of the key projects and their roles:
Here is the detailed structure of the solution:
Solution 'GRPC.NET7.Boilerplate' (6 of 6 projects)
|
├── GitHub Actions
├── External Sources
├── ClientApp
│ ├── GRPC.NET7.Client
│ │ ├── Helpers
│ │ │ ├── AuthHeaderInterceptor.cs
│ │ │ ├── TracerInterceptor.cs
│ │ ├── Interfaces
│ │ │ ├── AppTokenProvider.cs
│ │ │ ├── AuthService.cs
│ │ │ ├── Extension.cs
│ │ ├── Program.cs
├── Shared
│ ├── GRPC.NET7.Proto
│ │ ├── Helpers
│ │ │ ├── Utility.cs
│ │ ├── Authentication.cs
│ │ ├── BaseResponse.cs
│ │ ├── User.cs
├── GRPC.NET7.Api
│ ├── Properties
│ │ ├── launchSettings.json
│ ├── Converters
│ │ ├── TrimStringConverter.cs
│ ├── Helpers
│ │ ├── AppSettings.cs
│ │ ├── CustomException.cs
│ │ ├── CustomMapper.cs
│ │ ├── ExceptionHelpers.cs
│ │ ├── Extension.cs
│ │ ├── JwtAuthenticationManager.cs
│ │ ├── TimeStampContractResolver.cs
│ ├── Middleware
│ │ ├── Interceptors
│ │ │ ├── ExceptionInterceptor.cs
│ │ │ ├── LoggerInterceptor.cs
│ ├── Services
│ │ ├── AuthenticationHandler.cs
│ │ ├── UserHandler.cs
│ │ ├── appsettings.Development.json
│ │ ├── appsettings.json
│ │ ├── GlobalUsings.cs
│ │ ├── Program.cs
├── GRPC.NET7.Core
│ ├── AutoMapper
│ │ ├── AutoMapperProfile.cs
│ ├── Constants
│ ├── Dtos
│ │ ├── BaseResponseDto.cs
│ ├── Entities
│ │ ├── BaseEntity.cs
│ │ ├── UserEntity.cs
│ ├── Enums
│ │ ├── AppEnums.cs
│ ├── Interfaces
│ │ ├── Common
│ │ │ ├── IMapFrom.cs
│ │ ├── Repositories
│ │ │ ├── IBaseRepository.cs
│ │ │ ├── IUserRepository.cs
│ │ ├── Services
│ │ │ ├── IGreeterService.cs
│ │ │ ├── IUserService.cs
├── GRPC.NET7.Repository
│ ├── Dependencies
│ │ ├── Base
│ │ │ ├── BaseRepository.cs
│ ├── DatabaseContext
│ │ ├── AppDbContext.cs
│ ├── Migrations
│ │ ├── 20221204002240_initial.cs
│ │ ├── AppDbContextModelSnapshot.cs
│ ├── UserRepository.cs
├── GRPC.NET7.Service
│ ├── Dependencies
│ │ ├── Base
│ │ │ ├── GreeterService.cs
│ │ │ ├── UserService.cs
- Enables dual support for gRPC and RESTful APIs, allowing flexible communication with clients.
- Simplifies database interactions using the latest features of EF Core 7.0.0.
- Auto-generated interactive API documentation for seamless exploration and testing of endpoints.
- Advanced structured logging for superior debugging and monitoring capabilities.
- Minimizes boilerplate code with automated object-to-object mapping.
- Ensures smooth and type-safe transformations between Protocol Buffers, database entities, and Data Transfer Objects.
- Leverages generic programming to promote efficiency and maintainability.
This project adopts clean architecture principles, ensuring:
- Application Layer: Encapsulates core business logic and service contracts.
- Infrastructure Layer: Manages data access, repositories, and integrations.
- gRPC Layer: Serves as the entry point for gRPC endpoints and related logic.
Before running the application, ensure the following prerequisites are met:
-
Development Environment:
- Visual Studio 2022 or later.
- .NET 7 SDK installed.
-
Database:
- Set up the database connection string in the
appsettings.json
file under theGRPC.NET7.Api
project.
- Set up the database connection string in the
Follow these steps to set up and run the application:
-
Clone the Repository:
git clone https://github.com/biswajitpanday/Boilerplate.NET7gRPC.git
-
Open the Solution:
- Open the solution file (
GRPC.NET7.Boilerplate.sln
) in Visual Studio.
- Open the solution file (
-
Configure Database:
- Navigate to
GRPC.NET7.Api/appsettings.json
. - Update the
ConnectionStrings
section with your database connection string.
- Navigate to
-
Set Startup Projects:
- Right-click the solution and select
Properties
. - Under
Startup Project
, chooseMultiple Startup Projects
. - Set
GRPC.NET7.Api
andGRPC.NET7.Client
actions toStart
. - Click
Apply
, thenSave
.
- Right-click the solution and select
-
Run the Application:
After the client starts, a menu with five options will be displayed.
Choose an option to interact with the gRPC services. For example, you can authenticate or create a user using the predefined options.
The server console will display detailed logs of incoming requests and their processing.
Use these logs for debugging or to verify service functionality.
The client console shows the responses received from the server.
Contributions are highly encouraged! Follow these steps to get involved:
- Fork this repository.
- Create a new feature branch (
git checkout -b feature/your-feature-name
). - Commit your changes with clear messages (
git commit -m "Add: Feature description"
). - Push the branch and create a pull request.
Have questions or need support? Reach out via:
- GitHub Issues
- Email: [email protected]
- Convert the
GRPC.NET7.Proto
project into a standalone NuGet package for reuse in multiple services. - Add Swagger integration for API documentation (currently not functional).
The source code for this project is available on GitHub: Boilerplate.NET7gRPC
This project is licensed under the MIT License. See the LICENSE file for more details.