How to mock Autofaq interface with Moq
问题 Using C#/Autofac/Moq: I have this class: public class MyService { private readonly IlifetimeScope _scope; public MyService(ILifetimeScope scope) { _scope = scope; } public void DoWork() { var dbContext = _scope.Resolve<IDataContext>(); } } This works at runtime. However, I can't unit test it, since I cannot mock the Resolve() method. It is an extension method. What's the best way to be able to mock it? The obvious thing would be to inject the IDataContext in the constructor instead of the