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 11using System ;
2- using System . Collections . Generic ;
3- using System . Linq ;
4- using System . Text ;
5- using System . Threading . Tasks ;
2+ using NHibernate . Bytecode ;
63
74namespace NHibernate . Util
85{
96 internal static class ServiceProviderExtensions
107 {
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>
1116 public static object GetInstance ( this IServiceProvider serviceProvider , System . Type serviceType )
1217 {
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 ;
1526 }
1627 }
1728}
You can’t perform that action at this time.
0 commit comments