SharpAspect 1.1.3
See the version list below for details.
dotnet add package SharpAspect --version 1.1.3
NuGet\Install-Package SharpAspect -Version 1.1.3
<PackageReference Include="SharpAspect" Version="1.1.3" />
paket add SharpAspect --version 1.1.3
#r "nuget: SharpAspect, 1.1.3"
// Install SharpAspect as a Cake Addin #addin nuget:?package=SharpAspect&version=1.1.3 // Install SharpAspect as a Cake Tool #tool nuget:?package=SharpAspect&version=1.1.3
Getting Started
<a href="https://www.nuget.org/packages/SharpAspect/"> <img alt="Nuget (with prereleases)" src="https://img.shields.io/nuget/vpre/SharpAspect?label=SharpAspect%20%7C%20NuGet">
</a>
<a href="https://www.nuget.org/packages/SharpAspect/"> <img src="https://img.shields.io/nuget/dt/SharpAspect"> </a>
dotnet add package SharpAspect
Defining & mapping your Interceptors
All attributes must derive from MethodInterceptionAttribute class.
public class LogAttribute: MethodInterceptorAttribute
{
}
public class CacheAttribute: MethodInterceptorAttribute
{
}
<br>
All interceptors also must implement the IMethodInterceptor interface and should be marked with [Interceptor(typeof(TAttribute))]
.
[Interceptor(typeof(LogAttribute))]
public class LogInterceptor : IMethodInterceptor
{
public void AfterInvoke(IInvocation invocation)
{
// throw new System.NotImplementedException();
}
public void BeforeInvoke(IInvocation invocation)
{
System.Console.WriteLine($"[Logging] {invocation.Method.DeclaringType.FullName}.{invocation.Method.Name}");
}
public void OnError(IInvocation invocation, System.Exception e)
{
throw new System.NotImplementedException();
// System.Console.WriteLine(e.Message);
}
}
[Interceptor(typeof(CacheAttribute))]
public class CacheInterceptor : IMethodInterceptor
{
public void AfterInvoke(IInvocation invocation)
{
// throw new System.NotImplementedException();
}
public void BeforeInvoke(IInvocation invocation)
{
System.Console.WriteLine($"[Caching] {invocation.Method.DeclaringType.FullName}.{invocation.Method.Name}");
}
public void OnError(IInvocation invocation, System.Exception e)
{
throw new System.NotImplementedException();
}
}
Registering your services
private static IServiceProvider ConfigureServices()
{
return new ServiceCollection()
.EnableDynamicProxy()
// Transient service
.AddTransientProxy<IRocket, Rocket>()
.BuildServiceProvider();
}
public interface IRocket
{
void Launch();
string SetRoute(string route);
}
public class Rocket: IRocket
{
[Log]
public void Launch()
{
System.Console.WriteLine("Launching rocket in 3...2.....1 🚀");
}
[Log]
[Cache]
public string SetRoute(string route)
{
System.Console.WriteLine($"Route: {route}");
return route;
}
}
static void Main(string[] args)
{
var services = ConfigureServices();
var rocket = services.GetRequiredService<IRocket>();
rocket.SetRoute("Moon");
rocket.Launch();
}
Sample Output
[Logging] SharpAspect.Sample.IRocket.SetRoute
[Caching] SharpAspect.Sample.IRocket.SetRoute
Route: Moon
[Logging] SharpAspect.Sample.IRocket.Launch
Launching rocket in 3...2.....1 🚀
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Castle.Core (>= 4.4.1)
- Castle.Core.AsyncInterceptor (>= 1.7.0)
- Microsoft.Extensions.DependencyInjection (>= 3.1.8)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
A changelog is available at https://github.com/fasetto/SharpAspect/blob/master/CHANGELOG.md.