ComponentNotRegisteredException when trying to resolve from a Fake IContainer

StackOverflow https://stackoverflow.com/questions/21712598

  •  10-10-2022
  •  | 
  •  

سؤال

I'm trying to test out a part of my program that resolves instances of types. To do this I created a fake IContainer:

this.container = A.Fake<IContainer>();

However, when I reach this line of code:

container.Resolve<APresenter>();

It's throwing a ComponentNotRegisteredException!

How does the fake IContainer know to even throw that exception? The fake container should simply be a fake of the interface, not of the implementation. What's going on here?

هل كانت مفيدة؟

المحلول

It turns out IContainer.Resolve is an extension method of IContainer. It's not defined in the interface. I tried doing a whole bunch of setup on my Fake IContainer to get the extension method to work, but gave up after about an hour.

The far easier way was to create a Resolver interface and a wrapper around an Autofac IContainer.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top