File tree Expand file tree Collapse file tree 1 file changed +17
-6
lines changed Expand file tree Collapse file tree 1 file changed +17
-6
lines changed Original file line number Diff line number Diff line change 1
1
using System ;
2
- using System . Collections . Generic ;
3
- using System . Linq ;
4
- using System . Text ;
5
- using System . Threading . Tasks ;
2
+ using NHibernate . Bytecode ;
6
3
7
4
namespace NHibernate . Util
8
5
{
9
6
internal static class ServiceProviderExtensions
10
7
{
8
+ /// <summary>
9
+ /// Get a service, throwing if it cannot be resolved.
10
+ /// </summary>
11
+ /// <param name="serviceProvider">The service provider.</param>
12
+ /// <param name="serviceType">The service interface, base class or concrete implementation class.</param>
13
+ /// <returns>The service instance.</returns>
14
+ /// <exception cref="ArgumentNullException">thrown if <paramref name="serviceType"/> is <see langword="null" />.</exception>
15
+ /// <exception cref="HibernateServiceProviderException">thrown if the service cannot be resolved.</exception>
11
16
public static object GetInstance ( this IServiceProvider serviceProvider , System . Type serviceType )
12
17
{
13
- // 6.0 TODO throw a meaningful exception instead of using the Activator
14
- return serviceProvider . GetService ( serviceType ) ?? Activator . CreateInstance ( serviceType ) ;
18
+ if ( serviceType == null )
19
+ throw new ArgumentNullException ( nameof ( serviceType ) ) ;
20
+ var service = serviceProvider . GetService ( serviceType ) ;
21
+
22
+ if ( service == null )
23
+ throw new HibernateServiceProviderException (
24
+ $ "Unable to resolve an instance for { serviceType . AssemblyQualifiedName } ") ;
25
+ return service ;
15
26
}
16
27
}
17
28
}
You can’t perform that action at this time.
0 commit comments