Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use new hosting model for the app template. #10928

Merged
merged 17 commits into from
Dec 25, 2021
Merged

Use new hosting model for the app template. #10928

merged 17 commits into from
Dec 25, 2021

Conversation

maliming
Copy link
Member

@maliming maliming commented Dec 14, 2021

Resolve #6828
Resolve #10426

Changes:

  1. The Module class.

The PreConfigureServices, ConfigureServices, PostConfigureServices, OnPreApplicationInitialization, OnApplicationInitialization, OnPostApplicationInitialization methods of module have the Async version now. If you need to use an async method, please override the corresponding method. Async methods automatically call sync methods by default.

https://github.com/abpframework/abp/blob/new-hosting-model/framework/src/Volo.Abp.Core/Volo/Abp/Modularity/AbpModule.cs#L34-L109

  1. Unit Test.

Add the new AbpAsyncIntegratedTest and AbpAspNetCoreAsyncTestBase.

The test class needs to implement the IAsyncLifetime interface, which has been implemented by AbpAspNetCoreAsyncTestBase.

Demo test classes:
https://github.com/abpframework/abp/blob/new-hosting-model/framework/test/Volo.Abp.AspNetCore.Mvc.Tests/Volo/Abp/AspNetCore/Mvc/AbpAspNetCoreAsyncTestBase_Tests.cs

https://github.com/abpframework/abp/blob/new-hosting-model/framework/test/Volo.Abp.Core.Tests/Volo/Abp/DynamicProxy/AbpInterceptionTestBase.cs

  1. MVC
var builder = WebApplication.CreateBuilder(args);
builder.Host.AddAppSettingsSecretsJson()
    .UseAutofac();
await builder.Services.AddApplicationAsync<MyProjectNameWebModule>(options =>
{
    options.Services.ReplaceConfiguration(builder.Configuration);
});
var app = builder.Build();
await app.InitializeApplicationAsync();
await app.RunAsync();
  1. Blazor WASM
 var builder = WebAssemblyHostBuilder.CreateDefault(args);
var application = await builder.AddApplicationAsync<MyProjectNameBlazorModule>(options =>
{
    options.UseAutofac();
});
var host = builder.Build();
await application.InitializeApplicationAsync(host.Services);
await host.RunAsync();

Breaking changes:

If you use async methods in your module, please keep the same sync methods for compatibility.

eg: https://github.com/abpframework/abp/blob/new-hosting-model/modules/identityserver/src/Volo.Abp.IdentityServer.Domain/Volo/Abp/IdentityServer/AbpIdentityServerDomainModule.cs#L137-L163

Or

public async override Task OnApplicationInitializationAsync(ApplicationInitializationContext context)
{
    var options = context.ServiceProvider.GetRequiredService<IOptions<TokenCleanupOptions>>().Value;
    if (options.IsCleanupEnabled)
    {
        await context.ServiceProvider
            .GetRequiredService<IBackgroundWorkerManager>()
            .AddAsync(
                context.ServiceProvider
                    .GetRequiredService<TokenCleanupBackgroundWorker>()
            );
    }
}

public override void OnApplicationInitialization(ApplicationInitializationContext context)
{
    AsyncHelper.RunSync(() => OnApplicationInitializationAsync(context));
}

@maliming maliming added this to the 5.1-preview milestone Dec 14, 2021
@codecov

This comment has been minimized.

@maliming maliming marked this pull request as draft December 20, 2021 13:02
@maliming maliming removed the request for review from realLiangshiwei December 21, 2021 02:21
@hikalkan hikalkan requested review from hikalkan and enisn December 23, 2021 06:39
@rqx110

This comment has been minimized.

@maliming maliming marked this pull request as ready for review December 24, 2021 07:06
@maliming maliming requested a review from hikalkan December 24, 2021 07:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Consider using the new hosting model Async application initialization methods on the abpmodule class
3 participants