Skip to content

Commit

Permalink
Don't throw when config section is not present (#31)
Browse files Browse the repository at this point in the history
* Fix bug

* Update flow
  • Loading branch information
Tim-Maes authored Feb 13, 2025
1 parent cadbee0 commit e7360de
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/Bindicate/Bindicate.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<PackageTags>di, ioc, service, collection, extensions, attribute</PackageTags>
<PackageReleaseNotes>Add support for Decorators</PackageReleaseNotes>
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
<Version>1.7.0</Version>
<Version>1.7.1</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
16 changes: 8 additions & 8 deletions src/Bindicate/Configuration/AutowiringBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,15 @@ public AutowiringBuilder WithOptions(IConfiguration configuration)
{
var configSection = configuration.GetSection(attr.ConfigurationSection);

if (!configSection.Exists())
throw new InvalidOperationException($"Missing configuration section: {attr.ConfigurationSection}");

var genericOptionsConfigureMethod = typeof(OptionsConfigurationServiceCollectionExtensions)
.GetMethods()
.FirstOrDefault(m => m.Name == "Configure" && m.GetParameters().Length == 2);
if (configSection.Exists())
{
var genericOptionsConfigureMethod = typeof(OptionsConfigurationServiceCollectionExtensions)
.GetMethods()
.FirstOrDefault(m => m.Name == "Configure" && m.GetParameters().Length == 2);

var specializedMethod = genericOptionsConfigureMethod.MakeGenericMethod(type);
specializedMethod.Invoke(null, new object[] { _services, configSection });
var specializedMethod = genericOptionsConfigureMethod.MakeGenericMethod(type);
specializedMethod.Invoke(null, new object[] { _services, configSection });
}
}
}
}
Expand Down

0 comments on commit e7360de

Please sign in to comment.