-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Startup Async Initializers on Tenant Container created. #13169
Conversation
src/OrchardCore/OrchardCore.Abstractions/Modules/Builder/OrchardCoreBuilder.cs
Show resolved
Hide resolved
src/OrchardCore/OrchardCore.Abstractions/Modules/Builder/OrchardCoreBuilder.cs
Outdated
Show resolved
Hide resolved
src/OrchardCore/OrchardCore.Abstractions/Modules/Builder/OrchardCoreBuilder.cs
Outdated
Show resolved
Hide resolved
@@ -151,6 +149,22 @@ public static OrchardCoreBuilder AddDataAccess(this OrchardCoreBuilder builder) | |||
services.AddScoped<IDocumentStore, DocumentStore>(); | |||
services.AddSingleton<IFileDocumentStore, FileDocumentStore>(); | |||
services.AddTransient<IDbConnectionAccessor, DbConnectionAccessor>(); | |||
}) | |||
.InitializeServices(async serviceProvider => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name doesn't make it easy to understand what it does and when it's called.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm open to any name ;) It is executed when a shell container is built, so after all ConfigureServices()
and of course before all Configure()
used to build the tenant pipeline. It allows to init some services in an async way, here I use it to initialize the IStore
, see my 1st comment #13169 (comment)
.InitializeServices(async serviceProvider =>
{
var store = serviceProvider.GetService<IStore>();
if (store == null)
{
return;
}
await store.InitializeAsync();
...
});
Useful to init any Tenant Singleton Service in an async way when a tenant container is built.
Without having to define and register another service as this is integrated by the system.
But by defining in any module startup an
InitializeServicesAsync(IServiceProvider serviceProvider)
.Or by using the new
OCBuilder
helperbuilder.InitializeServices(async serviceProvider => ...
.In this PR we use the new
OCBuilder
extension helper to init the YesSqlIStore
.Note: The usage of the
OCBuilder
helper allows to do this kind of thing from the web application.