Is Func appropriate to use as a ctor arg when applying Dependency Injection?

前端 未结 7 509
没有蜡笔的小新
没有蜡笔的小新 2021-01-31 12:09

Example:

public class BusinessTransactionFactory  where T : IBusinessTransaction
{
    readonly Func _createTransactio         


        
相关标签:
7条回答
  • 2021-01-31 12:38

    @Steven's answer is very well thought out; personally I find limited use of Func<T> arguments readable.

    What I don't understand is the value of BusinessTransactionFactory<T> and IBusinessTransactionFactory<T>. These are just wrappers around the delegate. Presumably you're injecting IBusinessTransactionFactory<T> somewhere else. Why not just inject the delegate there?

    I think of Func<T> (and Func<T, TResult>, etc.) as factories. To me you have a factory class implementing a factory interface wrapping a factory delegate, and that seems redundant.

    0 讨论(0)
提交回复
热议问题