Skip to content

Commit

Permalink
Add IServiceCollection.AddOptions extension method.
Browse files Browse the repository at this point in the history
  • Loading branch information
RehanSaeed committed Oct 17, 2018
1 parent eacb408 commit 69bc976
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 5 deletions.
3 changes: 2 additions & 1 deletion Source/Boxed.AspNetCore/Boxed.AspNetCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</PropertyGroup>

<PropertyGroup Label="Package">
<VersionPrefix>2.1.0</VersionPrefix>
<VersionPrefix>2.2.0</VersionPrefix>
<Authors>Muhammad Rehan Saeed (RehanSaeed.com)</Authors>
<Product>ASP.NET Core Framework Boxed</Product>
<Description>Provides ASP.NET Core middleware, MVC filters, extension methods and helper code for an ASP.NET Core project.</Description>
Expand Down Expand Up @@ -45,6 +45,7 @@
<PackageReference Include="Microsoft.AspNetCore.Rewrite" Version="2.1.0" />
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="2.1.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="2.1.0" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="2.1.0" />
<PackageReference Condition="'$(OS)' == 'Windows_NT'" Include="Microsoft.SourceLink.GitHub" PrivateAssets="All" Version="1.0.0-beta-62925-02" />
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
<PackageReference Include="StyleCop.Analyzers" PrivateAssets="All" Version="1.1.0-beta007" />
Expand Down
17 changes: 17 additions & 0 deletions Source/Boxed.AspNetCore/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
namespace Boxed.AspNetCore
{
using System;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;

/// <summary>
/// <see cref="IServiceCollection"/> extension methods.
Expand Down Expand Up @@ -57,5 +59,20 @@ public static class ServiceCollectionExtensions

return services;
}

/// <summary>
/// Registers <see cref="IOptions{TOptions}"/> and <typeparamref name="TOptions"/> to the services container.
/// </summary>
/// <typeparam name="TOptions">The type of the options.</typeparam>
/// <param name="services">The services collection.</param>
/// <param name="configuration">The configuration.</param>
/// <returns>The same services collection.</returns>
public static IServiceCollection AddOptions<TOptions>(
this IServiceCollection services,
IConfiguration configuration)
where TOptions : class, new() =>
services
.Configure<TOptions>(configuration)
.AddSingleton(x => x.GetRequiredService<IOptions<TOptions>>().Value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<ItemGroup Label="Package References">
<PackageReference Include="Microsoft.AspNetCore.Mvc.Abstractions" Version="2.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.ApiExplorer" Version="2.1.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.8.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="Moq" Version="4.10.0" />
<PackageReference Include="StyleCop.Analyzers" PrivateAssets="All" Version="1.1.0-beta007" />
<PackageReference Include="xunit" Version="2.4.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

<ItemGroup Label="Package References">
<PackageReference Include="Microsoft.AspNetCore.Razor" Version="2.1.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.8.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="Moq" Version="4.10.0" />
<PackageReference Include="StyleCop.Analyzers" PrivateAssets="All" Version="1.1.0-beta007" />
<PackageReference Include="xunit" Version="2.4.0" />
Expand Down
2 changes: 1 addition & 1 deletion Tests/Boxed.AspNetCore.Test/Boxed.AspNetCore.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<ItemGroup Label="Package References">
<PackageReference Include="Microsoft.AspNetCore.Hosting" Version="2.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.1.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.8.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="Moq" Version="4.10.0" />
<PackageReference Include="StyleCop.Analyzers" PrivateAssets="All" Version="1.1.0-beta007" />
<PackageReference Include="xunit" Version="2.4.0" />
Expand Down
2 changes: 1 addition & 1 deletion Tests/Boxed.Mapping.Test/Boxed.Mapping.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</ItemGroup>

<ItemGroup Label="Package References">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.8.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="Moq" Version="4.10.0" />
<PackageReference Include="StyleCop.Analyzers" PrivateAssets="All" Version="1.1.0-beta007" />
<PackageReference Include="xunit" Version="2.4.0" />
Expand Down

0 comments on commit 69bc976

Please sign in to comment.