diff --git a/extensions/Sisk.IniConfiguration/Sisk.IniConfiguration.csproj b/extensions/Sisk.IniConfiguration/Sisk.IniConfiguration.csproj
index 264a0b4..86d6594 100644
--- a/extensions/Sisk.IniConfiguration/Sisk.IniConfiguration.csproj
+++ b/extensions/Sisk.IniConfiguration/Sisk.IniConfiguration.csproj
@@ -23,7 +23,7 @@
1.3.0
1.3.0
- 1.3.0-beta1
+ 1.3.0
en
LICENSE.txt
diff --git a/extensions/Sisk.SslProxy/Sisk.SslProxy.csproj b/extensions/Sisk.SslProxy/Sisk.SslProxy.csproj
index 4e5b292..af80c10 100644
--- a/extensions/Sisk.SslProxy/Sisk.SslProxy.csproj
+++ b/extensions/Sisk.SslProxy/Sisk.SslProxy.csproj
@@ -22,7 +22,7 @@
http-server,http,web framework
git
- 1.3-alpha6
+ 1.3-alpha7
1.3
1.3
diff --git a/src/Http/Hosting/HttpServerHostContextBuilder.cs b/src/Http/Hosting/HttpServerHostContextBuilder.cs
index 367bab4..09be918 100644
--- a/src/Http/Hosting/HttpServerHostContextBuilder.cs
+++ b/src/Http/Hosting/HttpServerHostContextBuilder.cs
@@ -266,7 +266,7 @@ public HttpServerHostContextBuilder UseRouter(Router r)
/// This method is an shortcut for calling .
///
/// An class which implements , or the router module itself.
- [RequiresUnreferencedCode(SR.Router_AutoScanModules_RequiresUnreferencedCode)]
+ [RequiresUnreferencedCode(SR.RequiresUnreferencedCode)]
public HttpServerHostContextBuilder UseAutoScan() where TModule : RouterModule
{
this._context.Router.AutoScanModules(typeof(TModule).Assembly);
@@ -278,7 +278,7 @@ public HttpServerHostContextBuilder UseAutoScan() where TModule : Route
///
/// An class which implements , or the router module itself.
/// The assembly where the scanning types are.
- [RequiresUnreferencedCode(SR.Router_AutoScanModules_RequiresUnreferencedCode)]
+ [RequiresUnreferencedCode(SR.RequiresUnreferencedCode)]
public HttpServerHostContextBuilder UseAutoScan(Assembly t) where TModule : RouterModule
{
this._context.Router.AutoScanModules(t);
diff --git a/src/Http/HttpContext.cs b/src/Http/HttpContext.cs
index 14f78da..952f20b 100644
--- a/src/Http/HttpContext.cs
+++ b/src/Http/HttpContext.cs
@@ -8,7 +8,9 @@
// Repository: https://github.com/sisk-http/core
using Sisk.Core.Entity;
+using Sisk.Core.Internal;
using Sisk.Core.Routing;
+using System.Diagnostics.CodeAnalysis;
namespace Sisk.Core.Http
{
@@ -17,7 +19,7 @@ namespace Sisk.Core.Http
///
public sealed class HttpContext
{
- internal static AsyncLocal _context = new AsyncLocal();
+ internal readonly static AsyncLocal _context = new AsyncLocal();
///
/// Gets the current running .
@@ -25,6 +27,7 @@ public sealed class HttpContext
///
/// This property is only accessible during an HTTP session, within the executing HTTP code.
///
+ [Experimental(DiagnosticId.Sisk_HttpContext_Current_Experimental)]
public static HttpContext Current { get => _context.Value ?? throw new InvalidOperationException(SR.HttpContext_InvalidThreadStaticAccess); }
///
diff --git a/src/Internal/DiagnosticId.cs b/src/Internal/DiagnosticId.cs
new file mode 100644
index 0000000..4d72305
--- /dev/null
+++ b/src/Internal/DiagnosticId.cs
@@ -0,0 +1,15 @@
+// The Sisk Framework source code
+// Copyright (c) 2024 PROJECT PRINCIPIUM
+//
+// The code below is licensed under the MIT license as
+// of the date of its publication, available at
+//
+// File name: DiagnosticId.cs
+// Repository: https://github.com/sisk-http/core
+
+namespace Sisk.Core.Internal;
+
+static class DiagnosticId
+{
+ public const string Sisk_HttpContext_Current_Experimental = "SISK0230";
+}
diff --git a/src/Internal/SR.cs b/src/Internal/SR.cs
index e227bbf..ac41574 100644
--- a/src/Internal/SR.cs
+++ b/src/Internal/SR.cs
@@ -59,7 +59,6 @@ static partial class SR
public const string HttpRequestEventSource_KeepAliveDisposed = "Cannot keep alive an instance that has it's connection disposed.";
- public const string Router_AutoScanModules_RequiresUnreferencedCode = "This method needs to search for types in your assembly, which can be trimmed in an AOT compilation.";
public const string Router_AutoScanModules_TModuleSameAssembly = "The TModule generic type must be a type that implements RouterModule and not RouterModule itself.";
public const string Router_Set_Collision = "A possible route collision could happen between route {0} and route {1}. Please review the methods and paths of these routes.";
public const string Router_Set_Exception = "Couldn't set method {0}.{1} as an route. See inner exception.";
@@ -101,6 +100,9 @@ static partial class SR
public const string Collection_ReadOnly = "Cannot insert items to this collection as it is read-only.";
+ public const string RequiresUnreferencedCode = "This method requires access to unreferenced code, which may break AOT compilation and trimming.";
+ public const string RequiresUnreferencedCode__RouterSetObject = "This method requires access to unreferenced code, which may break AOT compilation and trimming. Use the SetObject(Type, Object) or SetObject(TObject) overloads instead.";
+
public static string Format(string format, params object?[] items)
{
return String.Format(format, items);
diff --git a/src/Routing/Router__CoreSetters.cs b/src/Routing/Router__CoreSetters.cs
index 15c9b83..5f8e840 100644
--- a/src/Routing/Router__CoreSetters.cs
+++ b/src/Routing/Router__CoreSetters.cs
@@ -81,7 +81,7 @@ public bool IsDefined(RouteMethod method, string path)
///
/// An class which implements , or the router module itself.
/// The assembly to search the module type in.
- [RequiresUnreferencedCode(SR.Router_AutoScanModules_RequiresUnreferencedCode)]
+ [RequiresUnreferencedCode(SR.RequiresUnreferencedCode)]
public void AutoScanModules(Type moduleType, Assembly searchAssembly)
{
if (moduleType == typeof(RouterModule))
@@ -129,7 +129,7 @@ Abstract classes should not be included on the router.
///
/// An class which implements , or the router module itself.
/// The assembly to search in.
- [RequiresUnreferencedCode(SR.Router_AutoScanModules_RequiresUnreferencedCode)]
+ [RequiresUnreferencedCode(SR.RequiresUnreferencedCode)]
public void AutoScanModules(Assembly assembly) where TModule : RouterModule
=> this.AutoScanModules(typeof(TModule), assembly);
@@ -139,7 +139,7 @@ public void AutoScanModules(Assembly assembly) where TModule : RouterMo
/// for each type must be present.
///
/// An class which implements , or the router module itself.
- [RequiresUnreferencedCode(SR.Router_AutoScanModules_RequiresUnreferencedCode)]
+ [RequiresUnreferencedCode(SR.RequiresUnreferencedCode)]
public void AutoScanModules() where TModule : RouterModule
=> this.AutoScanModules(typeof(TModule).Assembly);
@@ -273,6 +273,7 @@ public void SetRoute(Route r)
///
/// The instance of the class where the methods are. The routing methods must be marked with any .
/// An exception is thrown when a method has an erroneous signature.
+ [RequiresUnreferencedCode(SR.RequiresUnreferencedCode__RouterSetObject)]
public void SetObject(object attrClassInstance)
{
Type attrClassType = attrClassInstance.GetType();
@@ -286,13 +287,25 @@ public void SetObject(object attrClassInstance)
/// for these methods.
///
/// The type of the class where the methods are. The routing methods must be marked with any .
- /// An exception is thrown when a method has an erroneous signature.
public void SetObject([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type attrClassType)
{
MethodInfo[] methods = attrClassType.GetMethods(SetObjectBindingFlag);
this.SetObjectInternal(methods, attrClassType, null);
}
+ ///
+ /// Searches for all instance and static methods that are marked with an attribute of
+ /// type in the specified object and creates routes
+ /// for these methods.
+ ///
+ /// The type of the class where the methods are. The routing methods must be marked with any .
+ /// The instance of the object where the route methods are.
+ public void SetObject([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type attrClassType, object instance)
+ {
+ MethodInfo[] methods = attrClassType.GetMethods(SetObjectBindingFlag);
+ this.SetObjectInternal(methods, attrClassType, instance);
+ }
+
///
/// Searches for all instance and static methods that are marked with an attribute of
/// type in the specified object and creates routes
@@ -305,6 +318,19 @@ public void SetObject([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes
this.SetObject(typeof(TObject));
}
+ ///
+ /// Searches for all instance and static methods that are marked with an attribute of
+ /// type in the specified object and creates routes
+ /// for these methods.
+ ///
+ /// The instance of to invoke the instance methods on.
+ /// The type of the class where the methods are. The routing methods must be marked with any .
+ /// An exception is thrown when a method has an erroneous signature.
+ public void SetObject<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] TObject>(TObject instance) where TObject : notnull
+ {
+ this.SetObject(typeof(TObject), instance);
+ }
+
private void SetObjectInternal(MethodInfo[] methods, Type callerType, object? instance)
{
RouterModule? rmodule = instance as RouterModule;
diff --git a/src/Sisk.Core.csproj b/src/Sisk.Core.csproj
index 8966219..a78320b 100644
--- a/src/Sisk.Core.csproj
+++ b/src/Sisk.Core.csproj
@@ -2,7 +2,7 @@
- net8.0
+ net8.0;net9.0
Sisk.Core
Debug;Release
@@ -47,7 +47,7 @@
1.3.0
1.3.0
- 1.3.0-rc5
+ 1.3.0