populateServiceCollection function
void
populateServiceCollection(
- ServiceCollection services,
- HostBuilderContext hostBuilderContext,
- HostEnvironment hostingEnvironment,
- Configuration appConfiguration,
- ServiceProvider serviceProviderGetter(),
Implementation
void populateServiceCollection(
ServiceCollection services,
HostBuilderContext hostBuilderContext,
HostEnvironment hostingEnvironment,
Configuration appConfiguration,
ServiceProvider Function() serviceProviderGetter,
) {
services
..addSingletonInstance<HostingEnvironment>(hostingEnvironment)
..addSingletonInstance<HostEnvironment>(hostingEnvironment)
..addSingletonInstance<HostBuilderContext>(hostBuilderContext)
..addSingletonInstance<Configuration>(appConfiguration)
..addSingleton<ApplicationLifetime>(
(s) => s.getService<HostApplicationLifetime>() as ApplicationLifetime,
)
..addSingleton<HostApplicationLifetime>(
(ServiceProvider s) => ApplicationLifetime(
(s.getRequiredService<LoggerFactory>())
.createLogger('ApplicationLifetime'),
),
)
..tryAdd(
ServiceDescriptor.singleton<Host>(
(_) {
var appServices = serviceProviderGetter();
return Host(
appServices,
appServices.getRequiredService<HostApplicationLifetime>(),
appServices
.getRequiredService<LoggerFactory>()
.createLogger('Host'),
appServices.getRequiredService<HostLifetime>(),
appServices.getRequiredService<Options<HostOptions>>(),
);
},
),
)
..configure<HostOptions>(HostOptions.new, (options) {
options.initialize(hostBuilderContext.configuration!);
})
..addLogging();
host_builder.addLifetime(services);
}