Skip to content

Startup class activation allow additional params #19809

@dazinator

Description

@dazinator

Startup classes cannot be activated with additional constructor params

When using a startup class, suppose I want my constructor to have some arbitrary additional parameters- like an ILogger, or an IOptions object. At the moment this is not allowed because the host builder doesnt know how to satisfy those additional constructor parameters when it activates the startup class. However in other situations such as UseMiddleware you can supply those additional parameter values to be used when activating the class, at the point of registering it. You cant do that currently when registering a Startup class. This means if in startup.cs you want to use something like an ILogger that you created in program.cs, you have to resort to accessing it in a static field like Program.Logger etc.

Describe the solution you'd like

The equivalent of
.UseStartup<Startup>(logger, foo, bar)

When the startup class is activated, any constructor parameters that the host doesn't natively know how to resolve, will be matched from the additional object instances supplied at the point of registering the startup class. This is a pattern found elsewhere in certain places in the framework.

Additional context

Add any other context or screenshots about the feature request here.

Metadata

Metadata

Assignees

Labels

area-hostingIncludes Hostingarea-networkingIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractionsenhancementThis issue represents an ask for new feature or an enhancement to an existing one

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions