Autofac - resolving runtime parameters without having to pass container around

后端 未结 3 975
时光取名叫无心
时光取名叫无心 2020-12-29 03:31

I have a simpler \"ServiceHelper\" class that takes two parameters in the constructor:

public ServiceHelper(ILogger log, string serviceN         


        
3条回答
  •  清酒与你
    2020-12-29 04:18

    I went down the path of the above approach and it works fine, however I found it impossible to unit test due to the fact the "Resolve<>" method in IContainer is a extension method. It also never really felt "right" with all the talk about not passing your container around.

    I went back to the drawing board, and found the "correct" way to instantiate objects using Autofac Delegate Factories http://docs.autofac.org/en/latest/advanced/delegate-factories.html

提交回复
热议问题