Browse Source

Add documentation for Swagger integration and logging in Single Layer Web Application template

pull/21728/head
ahmetfarukulu 2 years ago
parent
commit
0f2f07386c
  1. 70
      docs/en/solution-templates/single-layer-web-application/database-configurations.md
  2. BIN
      docs/en/solution-templates/single-layer-web-application/images/apply-database-migrations.png
  3. BIN
      docs/en/solution-templates/single-layer-web-application/images/database-connection-strings-modal.png
  4. BIN
      docs/en/solution-templates/single-layer-web-application/images/database-connection-strings.png
  5. 35
      docs/en/solution-templates/single-layer-web-application/logging.md
  6. 19
      docs/en/solution-templates/single-layer-web-application/swagger-integration.md

70
docs/en/solution-templates/single-layer-web-application/database-configurations.md

@ -109,6 +109,33 @@ protected override void OnModelCreating(ModelBuilder builder)
> The `Configure*` methods are extension methods defined in each module's `EntityFrameworkCore` project. These methods are used to configure the database schema for their respective modules.
### Configuration
In the `BookstoreModule` class, the `ConfigureEfCore` method is used to configure the database context. It registers the `BookstoreDbContext` class to the [dependency injection](../../framework/fundamentals/dependency-injection.md) system and sets the SQL Server as the default DBMS for the application.
```csharp
private void ConfigureEfCore(ServiceConfigurationContext context)
{
context.Services.AddAbpDbContext<BookstoreDbContext>(options =>
{
/* You can remove "includeAllEntities: true" to create
* default repositories only for aggregate roots
* Documentatidon: https://docs.abp.io/en/abp/latest/Entity-Framework-Core#add-default-repositories
*/
options.AddDefaultRepositories(includeAllEntities: true);
});
Configure<AbpDbContextOptions>(options =>
{
options.Configure(configurationContext =>
{
configurationContext.UseSqlServer();
});
});
}
```
## The `IDesignTimeDbContextFactory` Implementation
The `IDesignTimeDbContextFactory` interface is used to create a `DbContext` instance at design time. It is used by EF Core tools to create migrations and update the database. The `BookstoreDbContextFactory` class implements the `IDesignTimeDbContextFactory` interface to create a `BookstoreMigrationsDbContext` instance.
@ -138,37 +165,26 @@ public class BookstoreDbContextFactory : IDesignTimeDbContextFactory<BookstoreDb
}
```
## Configuration
## SaaS Module: The Tenant Management UI **\***
In the `BookstoreModule` class, the `ConfigureEfCore` method is used to configure the database context. It registers the `BookstoreDbContext` class to the [dependency injection](../../framework/fundamentals/dependency-injection.md) system and sets the SQL Server as the default DBMS for the application.
SaaS module provides the necessary UI to set and change connection string for tenants and trigger the database migrations.
```csharp
private void ConfigureEfCore(ServiceConfigurationContext context)
{
context.Services.AddAbpDbContext<BookstoreDbContext>(options =>
{
/* You can remove "includeAllEntities: true" to create
* default repositories only for aggregate roots
* Documentation: https://docs.abp.io/en/abp/latest/Entity-Framework-Core#add-default-repositories
*/
options.AddDefaultRepositories(includeAllEntities: true);
});
### The Connection String Management Modal
Configure<AbpDbContextOptions>(options =>
{
options.Configure(configurationContext =>
{
configurationContext.UseSqlServer();
});
});
}
```
You can click to the *Database Connection Strings* command in the *Actions* dropdown button for a tenant in the *Tenants* page of the SaaS module:
### SaaS Module: The Tenant Management UI **\***
![Database Connection Strings](images/database-connection-strings.png)
SaaS module provides the necessary UI to set and change connection string for tenants and trigger the database migrations.
It opens the *Database Connection Strings* modal as shown below:
#### The Connection String Management Modal
![Database Connection Strings Modal](images/database-connection-strings-modal.png)
You can click to the *Database Connection Strings* command in the *Actions* dropdown button for a tenant in the *Tenants* page of the SaaS module:
Here, we can set a *Default connection string* for the tenant.
When you make the changes and save the dialog, the database is automatically created and migrated. If you later update the connection string (for example if you change the database name), it will also trigger the database migration process again.
### Manually Applying the Database Migrations
If you need to manually trigger the database migrations for a specific tenant, click the *Actions* dropdown for the related tenant and select the *Apply Database Migrations* command on the *Tenant Management* page of the SaaS module:
![Apply Database Migrations](images/apply-database-migrations.png)

BIN
docs/en/solution-templates/single-layer-web-application/images/apply-database-migrations.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

BIN
docs/en/solution-templates/single-layer-web-application/images/database-connection-strings-modal.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

BIN
docs/en/solution-templates/single-layer-web-application/images/database-connection-strings.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 96 KiB

35
docs/en/solution-templates/single-layer-web-application/logging.md

@ -0,0 +1,35 @@
# Single Layer Solution: Logging
```json
//[doc-nav]
{
"Previous": {
"Name": "Database configurations",
"Path": "solution-templates/single-layer-web-application/database-configurations"
},
"Next": {
"Name": "Swagger integration",
"Path": "solution-templates/single-layer-web-application/swagger-integration"
}
}
```
The ABP Studio [single-layer solution template](index.md) is fully configured for [logging](../../framework/fundamentals/logging.md). All the applications are configured to use the [Serilog](https://serilog.net/) library for structured logging. They are configured in a common way for logging. This document explains that common logging structure.
## The Serilog Sinks
The Serilog library is configured so it writes the logs to the following targets (a.k.a. [sinks](https://github.com/serilog/serilog/wiki/Provided-Sinks)) in parallel:
* **[Console](https://github.com/serilog/serilog-sinks-console)**: Logs are written to the standard output of the executing application. Logging to console is useful when you want to see logs easily while it is running in a container.
* **[File](https://github.com/serilog/serilog-sinks-file)**: Logs are written to a file named `logs.txt` located under the `Logs` folder of the executing application. File logging is useful when you run the application on your local computer. You can check logs easily when you have a trouble. This sinks is only configured for DEBUG mode. It won't be available in your production environment (you can change the behavior in your `Program.cs` file).
* **ABP Studio**: This is a Sink provided by ABP Studio. It sends all logs to ABP Studio, so you can easily monitor your logs in real-time on your ABP Studio Application Monitoring panel.
The solution can work with [any sink](https://github.com/serilog/serilog/wiki/Provided-Sinks) supported by Serilog. You can add more sinks, remove pre-installed sinks or fine tune their configuration for your solution.
## Program.cs
The `Program.cs` file is the main point that configures the logging system. It is done here, because we want to initialize and start the logging in the very beginning of the application.
## Additional Information
We are using ABP Serilog Enrichers in the module class of the application. It is done by the `app.UseAbpSerilogEnrichers();` line in the `OnApplicationInitialization` method of your module class. That ASP.NET Core middleware adds current [tenant](../../framework/architecture/multi-tenancy/index.md), [user](../../framework/infrastructure/current-user.md), client and correlation id information to the log records.

19
docs/en/solution-templates/single-layer-web-application/swagger-integration.md

@ -0,0 +1,19 @@
# Single Layer Solution: Swagger Integration
```json
//[doc-nav]
{
"Previous": {
"Name": "Logging (with Serilog)",
"Path": "solution-templates/single-layer-web-application/logging"
},
"Next": {
"Name": "Multi-Tenancy",
"Path": "solution-templates/single-layer-web-application/multi-tenancy"
}
}
```
[Swagger](https://swagger.io/) is a tool that helps to create, document, and consume RESTful web services. It provides a user interface to interact with the APIs and also a way to generate client SDKs for the APIs.
In the [Swagger Integration](../../framework/api-development/swagger.md) document, you can find general information about Swagger integration with ABP Framework.
Loading…
Cancel
Save