From c2d8760c563da5f6182cb9475a1bb12c8622f455 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 23 Sep 2017 14:15:59 -0400 Subject: 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. --- .../Framework/InternalControllerFeatureProvider.cs | 27 ++++++++++++++++++++++ .../Framework/RewriteSubdomainRule.cs | 2 +- 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 src/StardewModdingAPI.Web/Framework/InternalControllerFeatureProvider.cs (limited to 'src/StardewModdingAPI.Web/Framework') 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 +{ + /// Discovers controllers with support for non-public controllers. + internal class InternalControllerFeatureProvider : ControllerFeatureProvider + { + /********* + ** Public methods + *********/ + /// Determines if a given type is a controller. + /// The candidate. + /// true if the type is a controller; otherwise false. + 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 { /// Rewrite requests to prepend the subdomain portion (if any) to the path. /// Derived from . - public class RewriteSubdomainRule : IRule + internal class RewriteSubdomainRule : IRule { /// Applies the rule. Implementations of ApplyRule should set the value for (defaults to RuleResult.ContinueRules). /// The rewrite context. -- cgit