BaseRuntime 1.0.0

The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package BaseRuntime --version 1.0.0
                    
NuGet\Install-Package BaseRuntime -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="BaseRuntime" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="BaseRuntime" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="BaseRuntime" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add BaseRuntime --version 1.0.0
                    
#r "nuget: BaseRuntime, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package BaseRuntime@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=BaseRuntime&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=BaseRuntime&version=1.0.0
                    
Install as a Cake Tool

WishingPool.AOP BaseRuntime

這個專案提供 AOP Runtime 的基礎元件與一個 MSBuild Task, 用來在編譯後以 IL 方式套用攔截邏輯。

內容與用途

  • AopExtensions
    • AddAop(IServiceProvider):初始化 AopServiceProvider 的靜態存取。
  • AopServiceProvider
    • 儲存全域 IServiceProvider,提供 GetRequiredService 取用 DI 服務。
  • AopInterceptorBase
    • 定義攔截器的基底介面(同步/非同步、泛型/非泛型)。
  • Attributes/AroundAttribute
    • 標記方法,指定攔截器型別。
  • Attributes/InterceptWithAttribute
    • 標記自訂 Attribute 類別,讓該 Attribute 指向攔截器型別。
  • BuildTask/AopCachePatchTask
    • 使用 Mono.Cecil 修改組件 IL:
      • 將被標記的方法複製為 $AopOriginal
      • 生成 $AopWrapper 包裝方法
      • 呼叫攔截器的 Around / AroundAsync
    • 透過 AroundAttribute 或 InterceptWithAttribute 解析攔截器型別。

基本使用方式

// 程式啟動時註冊
services.AddAop();

public class LoggingInterceptor : AopInterceptorBase
{
    public override Task AroundAsync(
        Func<object?[], Task> factory,
        string methodName,
        object?[] args,
        Attribute? attribute)
    {
        Console.WriteLine($"Before: {methodName}");
        return factory(args);
    }
}

public class ExampleService
{
    [Around(typeof(LoggingInterceptor))]
    public async Task DoWorkAsync()
    {
        await Task.Delay(10);
    }
}

Build Task 說明

AopCachePatchTask 需要在 MSBuild pipeline 中掛載並指定 AssemblyPath, 才能對輸出組件進行 patch。此專案目前只提供 Task 本體, 若要使用請在你的專案檔中自訂 Target 進行呼叫。

範例:在專案檔掛載 Task

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
  </PropertyGroup>

  
  <ItemGroup>
    <ProjectReference Include="..\BaseRuntime\BaseRuntime.csproj" />
  </ItemGroup>

  
  <UsingTask
    TaskName="Aop.Runtime.BuildTask.AopCachePatchTask"
    AssemblyFile="$(OutputPath)BaseRuntime.dll" />

  
  <Target Name="AopPatch" AfterTargets="Build">
    <AopCachePatchTask AssemblyPath="$(TargetPath)" />
  </Target>
</Project>

提醒:AssemblyFile 請指向包含 AopCachePatchTask 的組件輸出位置, 如果是 NuGet 套件,請改成對應的 $(Pkg... ) 路徑。

範例:使用 NuGet 套件時的寫法

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="WishingPool.AOP.BaseRuntime" Version="1.0.0" />
  </ItemGroup>

  <UsingTask
    TaskName="Aop.Runtime.BuildTask.AopCachePatchTask"
    AssemblyFile="$(PkgWishingPool_AOP_BaseRuntime)\lib\net8.0\BaseRuntime.dll" />

  <Target Name="AopPatch" AfterTargets="Build">
    <AopCachePatchTask AssemblyPath="$(TargetPath)" />
  </Target>
</Project>

提醒:$(PkgWishingPool_AOP_BaseRuntime) 會依 NuGet 套件 ID 轉為 Pkg + 底線化名稱(. 變 _)。版本號與 TFMs 請依實際套件調整。

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated