|
1 | | -# Pandatech.*** |
| 1 | +# Pandatech.SharedKernel.Postgres |
2 | 2 |
|
3 | | -## Introduction |
| 3 | +Welcome to the `Pandatech.SharedKernel.Postgres` NuGet package — a specialized extension of the Pandatech.SharedKernel |
| 4 | +designed to simplify PostgreSQL integration in your ASP.NET Core applications. This package provides a set of utilities |
| 5 | +and configurations to streamline the setup of Entity Framework Core with PostgreSQL, along with health checks and other |
| 6 | +enhancements. |
4 | 7 |
|
5 | | -## Features |
| 8 | +Although this package is primarily intended for internal use, it is publicly available for anyone who may find it |
| 9 | +useful. We recommend forking or copying the classes in this repository and creating your own package to suit your needs. |
| 10 | + |
| 11 | +## Key Features |
| 12 | + |
| 13 | +- **Simplified PostgreSQL Context Setup:** Easily configure your DbContext to use PostgreSQL with optimized settings. |
| 14 | +- **Automatic Database Migration:** Automatically apply pending migrations to the database on application startup. |
| 15 | +- **Decimal Type Configuration:** Globally configure the precision and scale for decimal properties. |
| 16 | +- **PostgreSQL Health Checks:** Integrate health checks for PostgreSQL to monitor database connectivity and health. |
| 17 | +- **Exception Handling:** Utilize exception processing to handle database-specific exceptions gracefully. |
| 18 | +- **Integration with SharedKernel:** Seamlessly integrates with Pandatech.SharedKernel and other PandaTech packages. |
| 19 | + |
| 20 | +## Prerequisites |
| 21 | + |
| 22 | +- .NET 9.0 SDK or higher |
| 23 | +- PostgreSQL database |
| 24 | +- Entity Framework Core Tools and Design packages |
6 | 25 |
|
7 | 26 | ## Installation |
8 | 27 |
|
9 | | -## Usage |
| 28 | +To install the `Pandatech.SharedKernel.Postgres` package, use the following command: |
| 29 | + |
| 30 | +```bash |
| 31 | +dotnet add package Pandatech.SharedKernel.Postgres |
| 32 | +``` |
| 33 | + |
| 34 | +Alternatively, you can add it via the NuGet Package Manager in Visual Studio, VS Code, or Rider. |
| 35 | + |
| 36 | +## Getting Started |
| 37 | + |
| 38 | +Follow these steps to integrate `Pandatech.SharedKernel.Postgres` into your ASP.NET Core application. |
| 39 | + |
| 40 | +### Step 1: Configure Connection String |
| 41 | + |
| 42 | +Add your PostgreSQL connection string to the `appsettings.{Environment}.json` file: |
| 43 | + |
| 44 | +```json |
| 45 | +{ |
| 46 | + "ConnectionStrings": { |
| 47 | + "Postgres": "Host=localhost;Database=mydatabase;Username=myusername;Password=mypassword" |
| 48 | + } |
| 49 | +} |
| 50 | +``` |
| 51 | + |
| 52 | +### Step 2: Modify Program.cs |
| 53 | + |
| 54 | +Update your `Program.cs` file to include the necessary configurations: |
| 55 | + |
| 56 | +```csharp |
| 57 | +using SharedKernel.Postgres.Extensions; |
| 58 | + |
| 59 | +var builder = WebApplication.CreateBuilder(args); |
| 60 | + |
| 61 | +// Add PostgreSQL context with the connection string |
| 62 | +builder.AddPostgresContext<MyDbContext>(builder.Configuration.GetConnectionString("Postgres")!); |
| 63 | + |
| 64 | +// Optionally add Gridify for data filtering and pagination |
| 65 | +builder.AddGridify(); // From Pandatech.Gridify.Extensions |
| 66 | +
|
| 67 | +var app = builder.Build(); |
| 68 | + |
| 69 | +// Apply pending migrations on startup |
| 70 | +app.MigrateDatabase<MyDbContext>(); |
| 71 | + |
| 72 | +app.Run(); |
| 73 | + |
| 74 | +``` |
| 75 | + |
| 76 | +By invoking `builder.AddPostgresContext<T>()`, the package automatically integrates PostgreSQL health checks using the |
| 77 | +`AspNetCore.HealthChecks.NpgSql` package. |
| 78 | + |
| 79 | +## Dependencies |
| 80 | + |
| 81 | +This package relies on several NuGet packages to provide extended functionality: |
| 82 | + |
| 83 | +- AspNetCore.HealthChecks.NpgSql: Health checks for PostgreSQL. |
| 84 | +- EntityFrameworkCore.Exceptions.PostgreSQL: Exception handling for EF Core and PostgreSQL. |
| 85 | +- Pandatech.EFCore.AuditBase: Audit logging for EF Core entities. |
| 86 | +- Pandatech.EFCore.PostgresExtensions: Additional extensions for EF Core and PostgreSQL. |
| 87 | +- PandaTech.FileExporter: Utilities for exporting files. |
| 88 | +- PandaTech.FluentImporter: Fluent API for importing data. |
| 89 | +- Pandatech.GridifyExtensions: Extensions for Gridify, simplifying data filtering and pagination. |
| 90 | +- Pandatech.SharedKernel: Core shared kernel functionalities. |
| 91 | + |
| 92 | +## Notes |
| 93 | + |
| 94 | +This library is designed primarily for internal use and, as such, does not include extensive documentation. For detailed |
| 95 | +information on the functionalities provided by the dependencies, please refer to their respective documentation. |
10 | 96 |
|
11 | 97 | ## License |
12 | 98 |
|
13 | | -Pandatech.*** is licensed under the MIT License. |
| 99 | +Pandatech.SharedKernel.Postgres is licensed under the MIT License. |
0 commit comments