Unity registration errors by type that I don't allow

I have an MVC4 application that uses Unity to resolve dependencies. One of the things that we have is the logger decorator for the Unity container - for the sole purpose of registering when a failure resolves any problem.

I find that there are a significant number of types that cannot decide that my application is NOT explicitly allowed. These types are:

IControllerFactory IControllerActivator IViewPageActivator ModelMetadataProvider ITempDataProvider IActionInvoker IAsyncActionInvoker 

Thrown exceptions look like this:

The ITempDataProvider type has no constructor available.

... with his type.

These exceptions occur only when the application starts, and now we register them and continue. Thus, the application works fine even after errors have occurred.

I hate swallowing mistakes without a good reason and without understanding that trying to solve them, first of all, I have no good reason.

Questions:

1) Does anyone know who / what is trying to solve them? This is nowhere in my codebase. 2) If somewhere within this framework they are trying to be resolved, is it expected that my application will grant Unity permission for them? 3) Or is this just the expected behavior, and should I catch these exceptions?

I understand that this is not so much, but I hope someone else sees these types of errors and can point me in the right direction.

+8
c # asp.net-mvc-4 unity-container
source share
2 answers

You have connected Unity as a DependencyResolver in MVC, right? All the types that you see are internally used by the MVC environment, and it (MVC) tries to solve them.

The MVC code under the hood catches an error if something is not resolved and returns to the standard implementation. This is done so that there is a single way to connect custom implementations of these things if you want them.

You do not need to do anything with these exceptions - just let them return to the caller and MVC will go right.

+7
source share

If you resolve a class through Unity, which does not have a constructor without parameters, Unity will recursively try to resolve parameter types for one of the constructors, unless you explicitly say no ... If this fails, you will get errors like those which you see for types that you may not have allowed directly. Therefore, it is likely that you are resolving your class, which has a constructor, which accepts an MVC class, which itself has constructor parameters, such as ModelMetaDataProvider , etc.

An example of a constructor instruction:

 <register type="IMyThing" mapTo="MyThing"> <constructor> <param name="x" type="MyType1" /> <param name="y" type="MyType2" /> </constructor> </register> 
+2
source share

All Articles