z4kn4fein / stashbox

A lightweight, fast, and portable dependency injection framework for .NET-based solutions.
https://z4kn4fein.github.io/stashbox
MIT License
141 stars 10 forks source link

[feature request] have more control over dependency overrides #165

Open kicsiede opened 6 months ago

kicsiede commented 6 months ago

It would be beneficial to have more precise control over passing dependency overrides, along with support for named bindings. Currently, our approach is as follows:

container.Resolve<Service>([ instance1, instance2... ])

In this setup, type overrides are automatically resolved based on their type and the classes/interfaces they implement, as far as I know.

I propose introducing a wrapper that the resolver could use to extract specific additional information, like this:

container.Resolve<Service>([ Arg<IExactType1>(instance1), Arg<IExactType2>("name", instance2)... ])

This approach would enable us to specify dependencies more explicitly and manage named bindings more effectively.

z4kn4fein commented 5 months ago

Hi @kicsiede, thank you for the suggestion, and sorry for the late reply! I'll look at both issues soon when I have more free time.

z4kn4fein commented 2 months ago

Hi @kicsiede, I've released v5.16.0, which allows dependency overrides to be expressed with a new Override type.

var service = container.Resolve<IService>([ Override.Of(instance, "name") ]);

Could you please check that it works for your use case? Thanks!