Skip to content

Dependency injection in .NET and WithParameter goodie #66071

Answered by pinkfloydx33
MartyIX asked this question in Q&A
Discussion options

You must be logged in to vote

You can use ActivatorUtilities.CreateInstance to pass in additional, non-DI parameters

services.AddSingleton(sp =>
   ActivatorUtilities.CreateInstance<DatabaseMain>(sp, appDataFolder)
);

There's a few other methods on ActivatorUtilities that can be used to support such scenarios and create factories that are aware of additional parameters.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@MartyIX
Comment options

Answer selected by MartyIX
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants