I am trying to register a Func<string> with TinyIoc.:
container.Register<Func<string>>(() => myObject.MyProperty);
and a type that depends on it with a constructor:
MyDependentType(Func<string> function)
when I use
container.Resolve<MyDependentType>()
it's all fine, but i cannot register a second Func<string> because it can not be resolved. It's ambigious I guess.
No Error is thrown, but the injected Func is the wrong one.
I tried to add names, no success.
Does TinyIoc actually support that? Or do I have to wrap my functions into objects? Like strategy pattern?
You are right, it is ambiguous to map the same type more than once. No DI container can handle this, because there is no way to tell one
Func<string>from anotherFunc<string>.That said, your usage example seems really unusual. Normally, if you want a property inside of another object, you inject the object that property belongs to, not a
Func<string>.