Skip to content

Commit

Permalink
Load internal Controllers as well as public ones
Browse files Browse the repository at this point in the history
  • Loading branch information
TheEadie committed Aug 3, 2023
1 parent 729b053 commit 7b3059d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
14 changes: 14 additions & 0 deletions src/hub/src/Worms.Gateway/InternalControllerProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.Reflection;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Controllers;

namespace Worms.Gateway;

/// <summary>
/// Overloads the default detection of controllers in ASP.NET Core to include controllers marked as internal
/// rather than just public.
/// </summary>
internal sealed class InternalControllerProvider : ControllerFeatureProvider
{
protected override bool IsController(TypeInfo typeInfo) => typeInfo.IsDefined(typeof(ApiControllerAttribute));
}
4 changes: 3 additions & 1 deletion src/hub/src/Worms.Gateway/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.IdentityModel.Tokens;
using Worms.Gateway;
using Worms.Gateway.Announcers;
using Worms.Gateway.Announcers.Slack;
using Worms.Gateway.Database;
Expand All @@ -10,7 +11,8 @@
builder.Logging.AddSimpleConsole(options => { options.SingleLine = true; });
builder.Configuration.AddEnvironmentVariables("WORMS_");

builder.Services.AddControllers();
builder.Services.AddControllers()
.ConfigureApplicationPartManager(manager => { manager.FeatureProviders.Add(new InternalControllerProvider()); });
builder.Services.AddApiVersioning();
builder.Services.AddAuthentication()
.AddJwtBearer(
Expand Down
8 changes: 4 additions & 4 deletions src/hub/src/Worms.Gateway/Worms.Gateway.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
<WarningsAsErrors>true</WarningsAsErrors>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Dapper" Version="2.0.143"/>
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="7.0.9"/>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="5.1.0"/>
<PackageReference Include="Npgsql" Version="7.0.4"/>
<PackageReference Include="Dapper" Version="2.0.143" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="7.0.9" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="5.1.0" />
<PackageReference Include="Npgsql" Version="7.0.4" />
</ItemGroup>
</Project>

0 comments on commit 7b3059d

Please sign in to comment.