Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Http;
using System.Web.Http.Controllers;
using System.Web.Http.Dependencies;

Expand All @@ -22,6 +23,8 @@ internal DependencyInjectionWebApiDependencyResolver( ApplicationDependencyInjec
{
this.di = di ?? throw new ArgumentNullException(nameof(di));
this.rootServiceProvider = rootServiceProvider ?? throw new ArgumentNullException( nameof( rootServiceProvider ) );

GlobalConfiguration.Configuration.DependencyResolver = this;
}

/// <summary>When <paramref name="serviceType"/> is for a <see cref="IHttpController"/> then the type will be resolved, otherwise an exception is thrown. Otherwise this method returns <c>null</c> if the type cannot be resolved or created.</summary>
Expand All @@ -39,7 +42,15 @@ public Object GetService(Type serviceType)
return this.di.ObjectFactoryCache.GetRequiredRootService( serviceType, useOverrides: true );
}

return this.di.ObjectFactoryCache.TryGetRootService( serviceType, useOverrides: true, out Object resolved ) ? resolved : null;
try
{
return this.di.ObjectFactoryCache.TryGetRootService( serviceType, useOverrides: true, out Object resolved ) ? resolved : null;
}
catch
{
// ASP.Net WebApi: all other dependencies are optional
return null;
}
}

/// <summary>Calls <see cref="GetService(Type)"/> by converting <paramref name="serviceType"/> to <see cref="IEnumerable{T}"/>.</summary>
Expand Down Expand Up @@ -92,7 +103,15 @@ public Object GetService( Type serviceType )
return this.di.ObjectFactoryCache.GetRequiredService( this.GetServiceProvider, serviceType, useOverrides: true );
}

return this.di.ObjectFactoryCache.TryGetService( this.GetServiceProvider, serviceType, useOverrides: true, out Object resolved ) ? resolved : null;
try
{
return this.di.ObjectFactoryCache.TryGetService( this.GetServiceProvider, serviceType, useOverrides: true, out Object resolved ) ? resolved : null;
}
catch
{
// ASP.Net WebApi: all other dependencies are optional
return null;
}
}

/// <summary>Calls <see cref="GetService(Type)"/> by converting <paramref name="serviceType"/> to <see cref="IEnumerable{T}"/>.</summary>
Expand Down