Search code examples
asp.net-web-api2dryioc

DryIoc: Enabling 'throwIfUnresolved' always throw an exception


I want to know name of dependencies that are missed (not injected)!

I Use this extensions:

  • DryIoc.dll v4.0.7
  • DryIoc.WebApi.dll v4.0.0
  • DryIoc.Web.dll v4.0.0

and I tried to use throwIfUnresolved parameter to solve the problem

Like this:

    public static void Register(HttpConfiguration config)
    {
        var container = new Container().WithWebApi(config, throwIfUnresolved: type => true);

        //...
    }

but after that I always get this exception even if there is no dependency!

DryIoc.ContainerException: 'Unable to resolve ModelMetadataProvider IsResolutionCall from Container with ambient ScopeContext DryIoc.AsyncExecutionFlowScopeContext without Scope Where no service registrations found and no dynamic registrations found in 0 of Rules.DynamicServiceProviders and nothing found in 0 of Rules.UnknownServiceResolvers'


Solution

  • Use this:

        public static void Register(HttpConfiguration config)
        {
            var container = new Container()
                .WithWebApi(
                    config,
                    throwIfUnresolved: type => type.IsController());
    
            //...
        }