3

I'm getting an error on this line of code:

    using (IMaterialClient rawMaterialServiceProxy =
ServerUtility.Container.Resolve<IMaterialClient>())

The error:

Resolution of the dependency failed... The current type, Xxx, is an interface and cannot be constructed. Are you missing a type mapping?

I'm not registering a concrete IMaterialClient. In the Pluralsight video I just watched, they said that you don't have to register every type because Unity will find an implementation if one wasn't specified. Has that changed? Am I missing something? Why won't that resolve? The assembly with the actual IMaterialClient implementation is in the bin folder when running this.

2 Answers 2

5

If they said that about Unity, they're wrong. Unity will resolve a concrete type (.Resolve<MyClass>), but interfaces have to be explicitly registered by associating them with concrete types.

There are extensions such as Unity Auto Registration to provide those features; I have no experience with them.

Sign up to request clarification or add additional context in comments.

Comments

5

I'm not aware of that feature in Unity. As far as I know, it will happily resolve unregistered concrete types, but has to have had a concrete type registered for any abstract types or interfaces. Best bet is to register it:

ServerUtility.Container.RegisterType<IMaterialClient, ConcreteMaterialClient>();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.