From 0002351b716f5950b02a46ee25ab6b752fadf5b4 Mon Sep 17 00:00:00 2001 From: ahmetfarukulu Date: Wed, 25 Dec 2024 08:27:30 +0300 Subject: [PATCH] Add implementation details for BookstoreDbSchemaMigrator in Db Migrator documentation --- .../db-migrator.md | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/docs/en/solution-templates/single-layer-web-application/db-migrator.md b/docs/en/solution-templates/single-layer-web-application/db-migrator.md index 3f8e24a4bd..988b16cef6 100644 --- a/docs/en/solution-templates/single-layer-web-application/db-migrator.md +++ b/docs/en/solution-templates/single-layer-web-application/db-migrator.md @@ -75,4 +75,33 @@ public async Task MigrateAsync() } ``` -The `BookstoreDbSchemaMigrator` class is used in the `MigrateDatabaseSchemaAsync` method for the database migration process. It is responsible for applying migrations to the database. \ No newline at end of file +The `BookstoreDbSchemaMigrator` class is used in the `MigrateDatabaseSchemaAsync` method for the database migration process. It is responsible for applying migrations to the database. + +```csharp +public class BookstoreDbSchemaMigrator : ITransientDependency +{ + private readonly IServiceProvider _serviceProvider; + + public BookstoreDbSchemaMigrator( + IServiceProvider serviceProvider) + { + _serviceProvider = serviceProvider; + } + + public async Task MigrateAsync() + { + + /* We intentionally resolving the BookstoreDbContext + * from IServiceProvider (instead of directly injecting it) + * to properly get the connection string of the current tenant in the + * current scope. + */ + + await _serviceProvider + .GetRequiredService() + .Database + .MigrateAsync(); + + } +} +``` \ No newline at end of file