Skip to content

[Question] Default services injected in other services? #557

@opinionmachine

Description

@opinionmachine

I am maintaining an app that mainly consists of a couple of APIs and websites. I am also building a CLI to set things up. Due to recent changes due to rising cost I have to make the setup a lot more complex and I would love to reuse some of the API code rather than reimplement things in the CLI. I want to have the same bugs everywhere, basically.

The problem is the that the API stuff is using an injected database connection factory that abstracts over reading secrets from config and dealing with rotated secrets, but it's a nice seam, and I'd like to make a simplified CLI only version that instead of reading cloud secrets just reads a connection string off the command line Options and use that to construct the factory, which allows all my old code to pretend like things are normal.

This does mean that I configure my AddTransient<IDbConnectionFactory, CliConnectionFactory> for constructor injection in DI, but then I need my CliConnectionFactory to be able to take CommandLineApplication in the constructor, but for all dependency services they are undefined, as the built-in classes only seem defined in the ServiceProvider implementation inside the CommandLineApplication. Would there be any way to achieve what I want or should I give up my dreams?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions