Skip to content

Commit

Permalink
fix: 修复Configuration被释放的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
withsalt committed Aug 15, 2022
1 parent 1826c52 commit 4d6db9e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 28 deletions.
52 changes: 26 additions & 26 deletions src/src/OnceMi.AspNetCore.OSS/OSSServiceExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,34 +31,34 @@ public static IServiceCollection AddOSSService(this IServiceCollection services,
/// <returns></returns>
public static IServiceCollection AddOSSService(this IServiceCollection services, string name, string key)
{
ServiceProvider provider = services.BuildServiceProvider();
IConfiguration configuration = provider.GetRequiredService<IConfiguration>();
if (configuration == null)
using (ServiceProvider provider = services.BuildServiceProvider())
{
throw new ArgumentNullException(nameof(IConfiguration));
}
provider.Dispose();

IConfigurationSection section = configuration.GetSection(key);
if (!section.Exists())
{
throw new Exception($"Config file not exist '{key}' section.");
}
OSSOptions options = section.Get<OSSOptions>();
if (options == null)
{
throw new Exception($"Get OSS option from config file failed.");
IConfiguration configuration = provider.GetRequiredService<IConfiguration>();
if (configuration == null)
{
throw new ArgumentNullException(nameof(IConfiguration));
}
IConfigurationSection section = configuration.GetSection(key);
if (!section.Exists())
{
throw new Exception($"Config file not exist '{key}' section.");
}
OSSOptions options = section.Get<OSSOptions>();
if (options == null)
{
throw new Exception($"Get OSS option from config file failed.");
}
return services.AddOSSService(name, o =>
{
o.AccessKey = options.AccessKey;
o.Endpoint = options.Endpoint;
o.IsEnableCache = options.IsEnableCache;
o.IsEnableHttps = options.IsEnableHttps;
o.Provider = options.Provider;
o.Region = options.Region;
o.SecretKey = options.SecretKey;
});
}
return services.AddOSSService(name, o =>
{
o.AccessKey = options.AccessKey;
o.Endpoint = options.Endpoint;
o.IsEnableCache = options.IsEnableCache;
o.IsEnableHttps = options.IsEnableHttps;
o.Provider = options.Provider;
o.Region = options.Region;
o.SecretKey = options.SecretKey;
});
}

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions src/src/OnceMi.AspNetCore.OSS/OnceMi.AspNetCore.OSS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
<Description>ASP.NET Core对象储存扩展。支持Minio自建对象储存、阿里云OSS、腾讯云COS、七牛云Kodo、华为云OBS</Description>
<Company>OnceMi</Company>
<Authors>OnceMi</Authors>
<Version>1.1.7</Version>
<Version>1.1.8</Version>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<RepositoryUrl>https://github.com/oncemi/OnceMi.AspNetCore.OSS</RepositoryUrl>
<PackageProjectUrl>https://github.com/oncemi/OnceMi.AspNetCore.OSS</PackageProjectUrl>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<RepositoryType>Github</RepositoryType>
<PackageReleaseNotes>修复阿里云put签名url判空问题 by staoran</PackageReleaseNotes>
<PackageReleaseNotes>修复Configuration被释放的问题</PackageReleaseNotes>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
Expand Down

0 comments on commit 4d6db9e

Please sign in to comment.