|
|
|
@ -1,6 +1,8 @@ |
|
|
|
using Microsoft.Extensions.Configuration; |
|
|
|
using JetBrains.Annotations; |
|
|
|
using Microsoft.Extensions.Configuration; |
|
|
|
using Microsoft.Extensions.DependencyInjection.Extensions; |
|
|
|
using Microsoft.Extensions.Hosting; |
|
|
|
using Volo.Abp; |
|
|
|
|
|
|
|
namespace Microsoft.Extensions.DependencyInjection; |
|
|
|
|
|
|
|
@ -11,7 +13,15 @@ public static class ServiceCollectionConfigurationExtensions |
|
|
|
return services.Replace(ServiceDescriptor.Singleton<IConfiguration>(configuration)); |
|
|
|
} |
|
|
|
|
|
|
|
[NotNull] |
|
|
|
public static IConfiguration GetConfiguration(this IServiceCollection services) |
|
|
|
{ |
|
|
|
return services.GetConfigurationOrNull() ?? |
|
|
|
throw new AbpException("Could not find an implementation of " + typeof(IConfiguration).AssemblyQualifiedName + " in the service collection."); |
|
|
|
} |
|
|
|
|
|
|
|
[CanBeNull] |
|
|
|
public static IConfiguration GetConfigurationOrNull(this IServiceCollection services) |
|
|
|
{ |
|
|
|
var hostBuilderContext = services.GetSingletonInstanceOrNull<HostBuilderContext>(); |
|
|
|
if (hostBuilderContext?.Configuration != null) |
|
|
|
@ -19,6 +29,6 @@ public static class ServiceCollectionConfigurationExtensions |
|
|
|
return hostBuilderContext.Configuration as IConfigurationRoot; |
|
|
|
} |
|
|
|
|
|
|
|
return services.GetSingletonInstance<IConfiguration>(); |
|
|
|
return services.GetSingletonInstanceOrNull<IConfiguration>(); |
|
|
|
} |
|
|
|
} |
|
|
|
|