I use the following class as a dependency converter. Got a link from http://www.asp.net/web-api/overview/advanced/dependency-injection
public class UnityWebAPIResolver : IDependencyResolver { protected IUnityContainer container; public UnityWebAPIResolver(IUnityContainer container) { if (container == null) { throw new ArgumentNullException("container"); } this.container = container; } public object GetService(Type serviceType) { try { return container.Resolve(serviceType); **
In the WebApiConfig class, after configuring the route, I configure the dependency converter as follows
config.DependencyResolver = new UnityWebAPIResolver(UnityConfig.GetContainer());
The problem is that I get several such errors.
InvalidOperationException - The type IHostBufferPolicySelector does not have an accessible constructor. InvalidOperationException - The type ModelMetadataProvider does not have an accessible constructor. InvalidOperationException - The type ITraceManager does not have an accessible constructor. InvalidOperationException - The type ITraceWriter does not have an accessible constructor. InvalidOperationException - The type IHttpControllerSelector does not have an accessible constructor. InvalidOperationException - The type IAssembliesResolver does not have an accessible constructor. InvalidOperationException - The type IHttpControllerTypeResolver does not have an accessible constructor. InvalidOperationException - The type IHttpActionSelector does not have an accessible constructor. InvalidOperationException - The type IActionValueBinder does not have an accessible constructor. InvalidOperationException - The type IContentNegotiator does not have an accessible constructor. InvalidOperationException - The type IHttpControllerActivator does not have an accessible constructor. InvalidOperationException - The type IBodyModelValidator does not have an accessible constructor.
Even if I try to do something similar in my global.asax, I get the same errors.
GlobalConfiguration.Configuration.DependencyResolver = new UnityWebAPIResolver(UnityConfig.GetContainer());
Question : All the dependencies in my API controller seem to be correctly entered , my only problem is that it cannot eliminate a few of the above (platform-specific) , is there any chance that this could lead to the failure of the whole system and cause random mistakes?
c # asp.net-web-api unity-container
Ather
source share