summaryrefslogtreecommitdiff
path: root/src/StardewModdingAPI.Web/Framework
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2017-09-23 14:15:59 -0400
committerJesse Plamondon-Willard <github@jplamondonw.com>2017-09-23 14:15:59 -0400
commitc2d8760c563da5f6182cb9475a1bb12c8622f455 (patch)
tree3be890596b387263b98d96332e283ada8e08d7c6 /src/StardewModdingAPI.Web/Framework
parenteaabd91f31db35e050b7215f5f36568bf6982a83 (diff)
downloadSMAPI-c2d8760c563da5f6182cb9475a1bb12c8622f455.tar.gz
SMAPI-c2d8760c563da5f6182cb9475a1bb12c8622f455.tar.bz2
SMAPI-c2d8760c563da5f6182cb9475a1bb12c8622f455.zip
make web controllers internal (#336)
This is needed to support internal models, which is needed to share the models with the main SMAPI assembly without making them visible to mods.
Diffstat (limited to 'src/StardewModdingAPI.Web/Framework')
-rw-r--r--src/StardewModdingAPI.Web/Framework/InternalControllerFeatureProvider.cs27
-rw-r--r--src/StardewModdingAPI.Web/Framework/RewriteSubdomainRule.cs2
2 files changed, 28 insertions, 1 deletions
diff --git a/src/StardewModdingAPI.Web/Framework/InternalControllerFeatureProvider.cs b/src/StardewModdingAPI.Web/Framework/InternalControllerFeatureProvider.cs
new file mode 100644
index 00000000..2c24c610
--- /dev/null
+++ b/src/StardewModdingAPI.Web/Framework/InternalControllerFeatureProvider.cs
@@ -0,0 +1,27 @@
+using System;
+using System.Reflection;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Mvc.Controllers;
+
+namespace StardewModdingAPI.Web.Framework
+{
+ /// <summary>Discovers controllers with support for non-public controllers.</summary>
+ internal class InternalControllerFeatureProvider : ControllerFeatureProvider
+ {
+ /*********
+ ** Public methods
+ *********/
+ /// <summary>Determines if a given type is a controller.</summary>
+ /// <param name="type">The <see cref="T:System.Reflection.TypeInfo" /> candidate.</param>
+ /// <returns><code>true</code> if the type is a controller; otherwise <code>false</code>.</returns>
+ protected override bool IsController(TypeInfo type)
+ {
+ return
+ type.IsClass
+ && !type.IsAbstract
+ && (/*type.IsPublic &&*/ !type.ContainsGenericParameters)
+ && (!type.IsDefined(typeof(NonControllerAttribute))
+ && (type.Name.EndsWith("Controller", StringComparison.OrdinalIgnoreCase) || type.IsDefined(typeof(ControllerAttribute))));
+ }
+ }
+}
diff --git a/src/StardewModdingAPI.Web/Framework/RewriteSubdomainRule.cs b/src/StardewModdingAPI.Web/Framework/RewriteSubdomainRule.cs
index 9b89cb65..5a56844f 100644
--- a/src/StardewModdingAPI.Web/Framework/RewriteSubdomainRule.cs
+++ b/src/StardewModdingAPI.Web/Framework/RewriteSubdomainRule.cs
@@ -5,7 +5,7 @@ namespace StardewModdingAPI.Web.Framework
{
/// <summary>Rewrite requests to prepend the subdomain portion (if any) to the path.</summary>
/// <remarks>Derived from <a href="https://stackoverflow.com/a/44526747/262123" />.</remarks>
- public class RewriteSubdomainRule : IRule
+ internal class RewriteSubdomainRule : IRule
{
/// <summary>Applies the rule. Implementations of ApplyRule should set the value for <see cref="RewriteContext.Result" /> (defaults to RuleResult.ContinueRules).</summary>
/// <param name="context">The rewrite context.</param>