Example:
public class BusinessTransactionFactory where T : IBusinessTransaction
{
readonly Func _createTransactio
I personally don't like to see Func
arguments as dependencies in my classes, because I think it makes the code less readable, but I know many developers don't agree with me. Some containers, such as Autofac, even allows you to resolve Func
delegates (by returning a () => container.Resolve
).
There are however, two cases where I don't mind to inject Func
delegates:
Func
constructor argument is located in the Composition Root, because in that case it's part of the container's configuration and I don't consider that part of the design of the application.Func
is injected in a single type in the application. When more services start depending on that same Func
, it would be better for readability to create a special I[SomeType]Factory
interface and inject that.