From 554960d59626fc355a67f063dc6d375e3fa23844 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Halil=20=C4=B0brahim=20Kalkan?= Date: Wed, 27 Apr 2022 22:25:05 +0300 Subject: [PATCH] Revise the Module-Development-Basics.md document. --- docs/en/Module-Development-Basics.md | 41 ++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/docs/en/Module-Development-Basics.md b/docs/en/Module-Development-Basics.md index 17c0e91808..dd01f81ff4 100644 --- a/docs/en/Module-Development-Basics.md +++ b/docs/en/Module-Development-Basics.md @@ -59,13 +59,15 @@ public class BlogModule : AbpModule } ```` +> `ConfigureServices` method has an asynchronous version too: `ConfigureServicesAsync`. If you want to make asynchronous calls (use the `await` keyword) inside this method, override the asynchronous version instead of the synchronous one. If you override both asynchronous and synchronous versions, only the asynchronous version will be executed. + See the [Configuration](Configuration.md) document for more about the configuration system. #### Pre & Post Configure Services ``AbpModule`` class also defines ``PreConfigureServices`` and ``PostConfigureServices`` methods to override and write your code just before and just after ``ConfigureServices``. Notice that the code you have written into these methods will be executed before/after the ``ConfigureServices`` methods of all other modules. -> These methods have Async versions too, and if you want to make asynchronous calls inside these methods, override the asynchronous versions instead of the synchronous ones. +> These methods have asynchronous versions too. If you want to make asynchronous calls inside these methods, override the asynchronous versions instead of the synchronous ones. ### Application Initialization @@ -73,37 +75,48 @@ Once all the services of all modules are configured, the application starts by i #### OnApplicationInitialization Method -You can override ``OnApplicationInitialization`` method to execute code while application is being started. Example: +You can override ``OnApplicationInitialization`` method to execute code while application is being started. -> These methods have Async versions too, and if you want to make asynchronous calls inside these methods, override the asynchronous versions instead of the synchronous ones. +**Example:** ````C# public class BlogModule : AbpModule { - // Asynchronous methods call synchronous methods by default, You only need to implement one of them. - - public override Task OnApplicationInitializationAsync(ApplicationInitializationContext context) + public override void OnApplicationInitialization( + ApplicationInitializationContext context) { var myService = context.ServiceProvider.GetService(); - await myService.DoSomethingAsync(); + myService.DoSomething(); } +} +```` - public override void OnApplicationInitialization(ApplicationInitializationContext context) +`OnApplicationInitialization` method has an asynchronous version too. If you want to make asynchronous calls (use the `await` keyword) inside this method, override the asynchronous version instead of the synchronous one. + +**Example:** + +````csharp +public class BlogModule : AbpModule +{ + public override Task OnApplicationInitializationAsync( + ApplicationInitializationContext context) { var myService = context.ServiceProvider.GetService(); - myService.DoSomething(); + await myService.DoSomethingAsync(); } } ```` -``OnApplicationInitialization`` is generally used by the startup module to construct the middleware pipeline for ASP.NET Core applications. Example: +> If you override both asynchronous and synchronous versions, only the asynchronous version will be executed. + +``OnApplicationInitialization`` is generally used by the startup module to construct the middleware pipeline for ASP.NET Core applications. + +**Example:** ````C# [DependsOn(typeof(AbpAspNetCoreMvcModule))] public class AppModule : AbpModule { - //... - public override void OnApplicationInitialization(ApplicationInitializationContext context) { var app = context.GetApplicationBuilder(); @@ -125,10 +138,14 @@ You can also perform startup logic if your module requires it ``AbpModule`` class also defines ``OnPreApplicationInitialization`` and ``OnPostApplicationInitialization`` methods to override and write your code just before and just after ``OnApplicationInitialization``. Notice that the code you have written into these methods will be executed before/after the ``OnApplicationInitialization`` methods of all other modules. +> These methods have asynchronous versions too, and if you want to make asynchronous calls inside these methods, override the asynchronous versions instead of the synchronous ones. + ### Application Shutdown Lastly, you can override ``OnApplicationShutdown`` method if you want to execute some code while application is being shutdown. +> This methods has asynchronous version too. If you want to make asynchronous calls inside this method, override the asynchronous version instead of the synchronous one. + ## Module Dependencies In a modular application, it's not unusual for one module to depend upon another module(s). An Abp module must declare ``[DependsOn]`` attribute if it does have a dependency upon another module, as shown below: