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

前端 未结 7 530
没有蜡笔的小新
没有蜡笔的小新 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 arguments readable.

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

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

提交回复
热议问题