Skip to content

Commit

Permalink
upstream 1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
CypherPotato committed Nov 13, 2024
1 parent 7e6c379 commit 2760369
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

<AssemblyVersion>1.3.0</AssemblyVersion>
<FileVersion>1.3.0</FileVersion>
<Version>1.3.0-beta1</Version>
<Version>1.3.0</Version>

<NeutralLanguage>en</NeutralLanguage>
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
Expand Down
2 changes: 1 addition & 1 deletion extensions/Sisk.SslProxy/Sisk.SslProxy.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<PackageTags>http-server,http,web framework</PackageTags>
<RepositoryType>git</RepositoryType>

<Version>1.3-alpha6</Version>
<Version>1.3-alpha7</Version>
<AssemblyVersion>1.3</AssemblyVersion>
<FileVersion>1.3</FileVersion>

Expand Down
4 changes: 2 additions & 2 deletions src/Http/Hosting/HttpServerHostContextBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ public HttpServerHostContextBuilder UseRouter(Router r)
/// This method is an shortcut for calling <see cref="Router.AutoScanModules{T}()"/>.
/// </summary>
/// <typeparam name="TModule">An class which implements <see cref="RouterModule"/>, or the router module itself.</typeparam>
[RequiresUnreferencedCode(SR.Router_AutoScanModules_RequiresUnreferencedCode)]
[RequiresUnreferencedCode(SR.RequiresUnreferencedCode)]
public HttpServerHostContextBuilder UseAutoScan<TModule>() where TModule : RouterModule
{
this._context.Router.AutoScanModules<TModule>(typeof(TModule).Assembly);
Expand All @@ -278,7 +278,7 @@ public HttpServerHostContextBuilder UseAutoScan<TModule>() where TModule : Route
/// </summary>
/// <typeparam name="TModule">An class which implements <see cref="RouterModule"/>, or the router module itself.</typeparam>
/// <param name="t">The assembly where the scanning types are.</param>
[RequiresUnreferencedCode(SR.Router_AutoScanModules_RequiresUnreferencedCode)]
[RequiresUnreferencedCode(SR.RequiresUnreferencedCode)]
public HttpServerHostContextBuilder UseAutoScan<TModule>(Assembly t) where TModule : RouterModule
{
this._context.Router.AutoScanModules<TModule>(t);
Expand Down
5 changes: 4 additions & 1 deletion src/Http/HttpContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -17,14 +19,15 @@ namespace Sisk.Core.Http
/// </summary>
public sealed class HttpContext
{
internal static AsyncLocal<HttpContext?> _context = new AsyncLocal<HttpContext?>();
internal readonly static AsyncLocal<HttpContext?> _context = new AsyncLocal<HttpContext?>();

/// <summary>
/// Gets the current running <see cref="HttpContext"/>.
/// </summary>
/// <remarks>
/// This property is only accessible during an HTTP session, within the executing HTTP code.
/// </remarks>
[Experimental(DiagnosticId.Sisk_HttpContext_Current_Experimental)]
public static HttpContext Current { get => _context.Value ?? throw new InvalidOperationException(SR.HttpContext_InvalidThreadStaticAccess); }

/// <summary>
Expand Down
15 changes: 15 additions & 0 deletions src/Internal/DiagnosticId.cs
Original file line number Diff line number Diff line change
@@ -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";
}
4 changes: 3 additions & 1 deletion src/Internal/SR.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.";
Expand Down Expand Up @@ -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>(TObject) overloads instead.";

public static string Format(string format, params object?[] items)
{
return String.Format(format, items);
Expand Down
34 changes: 30 additions & 4 deletions src/Routing/Router__CoreSetters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public bool IsDefined(RouteMethod method, string path)
/// </summary>
/// <param name="moduleType">An class which implements <see cref="RouterModule"/>, or the router module itself.</param>
/// <param name="searchAssembly">The assembly to search the module type in.</param>
[RequiresUnreferencedCode(SR.Router_AutoScanModules_RequiresUnreferencedCode)]
[RequiresUnreferencedCode(SR.RequiresUnreferencedCode)]
public void AutoScanModules(Type moduleType, Assembly searchAssembly)
{
if (moduleType == typeof(RouterModule))
Expand Down Expand Up @@ -129,7 +129,7 @@ Abstract classes should not be included on the router.
/// </summary>
/// <typeparam name="TModule">An class which implements <see cref="RouterModule"/>, or the router module itself.</typeparam>
/// <param name="assembly">The assembly to search <typeparamref name="TModule"/> in.</param>
[RequiresUnreferencedCode(SR.Router_AutoScanModules_RequiresUnreferencedCode)]
[RequiresUnreferencedCode(SR.RequiresUnreferencedCode)]
public void AutoScanModules<TModule>(Assembly assembly) where TModule : RouterModule
=> this.AutoScanModules(typeof(TModule), assembly);

Expand All @@ -139,7 +139,7 @@ public void AutoScanModules<TModule>(Assembly assembly) where TModule : RouterMo
/// for each type must be present.
/// </summary>
/// <typeparam name="TModule">An class which implements <see cref="RouterModule"/>, or the router module itself.</typeparam>
[RequiresUnreferencedCode(SR.Router_AutoScanModules_RequiresUnreferencedCode)]
[RequiresUnreferencedCode(SR.RequiresUnreferencedCode)]
public void AutoScanModules<TModule>() where TModule : RouterModule
=> this.AutoScanModules<TModule>(typeof(TModule).Assembly);

Expand Down Expand Up @@ -273,6 +273,7 @@ public void SetRoute(Route r)
/// </summary>
/// <param name="attrClassInstance">The instance of the class where the methods are. The routing methods must be marked with any <see cref="RouteAttribute"/>.</param>
/// <exception cref="Exception">An exception is thrown when a method has an erroneous signature.</exception>
[RequiresUnreferencedCode(SR.RequiresUnreferencedCode__RouterSetObject)]
public void SetObject(object attrClassInstance)
{
Type attrClassType = attrClassInstance.GetType();
Expand All @@ -286,13 +287,25 @@ public void SetObject(object attrClassInstance)
/// for these methods.
/// </summary>
/// <param name="attrClassType">The type of the class where the methods are. The routing methods must be marked with any <see cref="RouteAttribute"/>.</param>
/// <exception cref="Exception">An exception is thrown when a method has an erroneous signature.</exception>
public void SetObject([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type attrClassType)
{
MethodInfo[] methods = attrClassType.GetMethods(SetObjectBindingFlag);
this.SetObjectInternal(methods, attrClassType, null);
}

/// <summary>
/// Searches for all instance and static methods that are marked with an attribute of
/// type <see cref="RouteAttribute"/> in the specified object and creates routes
/// for these methods.
/// </summary>
/// <param name="attrClassType">The type of the class where the methods are. The routing methods must be marked with any <see cref="RouteAttribute"/>.</param>
/// <param name="instance">The instance of the object where the route methods are.</param>
public void SetObject([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type attrClassType, object instance)
{
MethodInfo[] methods = attrClassType.GetMethods(SetObjectBindingFlag);
this.SetObjectInternal(methods, attrClassType, instance);
}

/// <summary>
/// Searches for all instance and static methods that are marked with an attribute of
/// type <see cref="RouteAttribute"/> in the specified object and creates routes
Expand All @@ -305,6 +318,19 @@ public void SetObject([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes
this.SetObject(typeof(TObject));
}

/// <summary>
/// Searches for all instance and static methods that are marked with an attribute of
/// type <see cref="RouteAttribute"/> in the specified object and creates routes
/// for these methods.
/// </summary>
/// <param name="instance">The instance of <typeparamref name="TObject"/> to invoke the instance methods on.</param>
/// <typeparam name="TObject">The type of the class where the methods are. The routing methods must be marked with any <see cref="RouteAttribute"/>.</typeparam>
/// <exception cref="Exception">An exception is thrown when a method has an erroneous signature.</exception>
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;
Expand Down
4 changes: 2 additions & 2 deletions src/Sisk.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<!-- supported frameworks -->
<PropertyGroup>
<TargetFrameworks>net8.0</TargetFrameworks>
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
<RootNamespace>Sisk.Core</RootNamespace>
<Configurations>Debug;Release</Configurations>
</PropertyGroup>
Expand Down Expand Up @@ -47,7 +47,7 @@
<PropertyGroup>
<AssemblyVersion>1.3.0</AssemblyVersion>
<FileVersion>1.3.0</FileVersion>
<Version>1.3.0-rc5</Version>
<Version>1.3.0</Version>
</PropertyGroup>

<!-- licensing, readme, signing -->
Expand Down

0 comments on commit 2760369

Please sign in to comment.