mirror of https://github.com/abpframework/abp
				
				
				
			
							parent
							
								
									e10e0881e1
								
							
						
					
					
						commit
						38dc378db3
					
				| @ -0,0 +1,26 @@ | ||||
| using System; | ||||
| using System.Linq; | ||||
| 
 | ||||
| namespace Microsoft.Extensions.DependencyInjection | ||||
| { | ||||
|     public static class ServiceCollectionCommonExtensions | ||||
|     { | ||||
|         public static T GetSingletonInstanceOrNull<T>(this IServiceCollection services) | ||||
|         { | ||||
|             return (T)services | ||||
|                 .FirstOrDefault(d => d.ServiceType == typeof(T)) | ||||
|                 ?.ImplementationInstance; | ||||
|         } | ||||
| 
 | ||||
|         public static T GetSingletonInstance<T>(this IServiceCollection services) | ||||
|         { | ||||
|             var service = services.GetSingletonInstanceOrNull<T>(); | ||||
|             if (service == null) | ||||
|             { | ||||
|                 throw new InvalidOperationException("Could not find singleton service: " + typeof(T).AssemblyQualifiedName); | ||||
|             } | ||||
| 
 | ||||
|             return service; | ||||
|         } | ||||
|     } | ||||
| } | ||||
					Loading…
					
					
				
		Reference in new issue
	
	 Halil İbrahim Kalkan
						Halil İbrahim Kalkan