byme8 / ZeroIoC

ZeroIoC is reflectionless IoC Container for C#
MIT License
44 stars 5 forks source link

Func<T> and Lazy<T> ctor parameters #7

Open appel1 opened 4 months ago

appel1 commented 4 months ago

Perhaps not possible, but it would be a useful convenience feature to be able to have func and lazy parameters that can be used as factory methods instead of going via the ZeroIoCContainer.Resolve method. To be able to reduce the places in the code base that has to be "aware" of the container.

byme8 commented 4 months ago

I'm having a bit of trouble understanding how "using func and lazy parameters as factory methods" would work and how it would improve the workflow.

Could you provide more details or an example to clarify?

appel1 commented 4 months ago

Sorry.

So I can do something like this instead of having to make SomeClass aware of the IoC container. In some cases it also makes it easier in unit tests where you can just provide a delegate instead of having to setup a full container.

public class SomeClass(Func<SomeDependency> factory)
{
    public int DoSomething() => factory().Something();
}