LOOM.NET : An AOP Weaver Library
2007-06-27 13:58
162 查看
LOOM.NET 是波茨坦大学的一个研究项目, 它采用 Emit IL 的方式实现代码与Aspect的编织, 现在有两个子项目, 分别是Runtime weaver: Rapier-LOOM.NET 和 Static weaver: Gripper-LOOM.NET.
下面的示例代码演示了如何使用 Rapier-LOOM.NET 来监视一个方法的运行时间
using System;
using System.Collections.Generic;
using System.Text;
using Loom;
using Loom.JoinPoints;
namespace Monitoring
{
class Program
{
static void Main(string[] args)
{
MonitoringAspect monAspect = new MonitoringAspect();
// interweave with the monitoring aspect
MathLibrary lib = Weaver.Create<MathLibrary>(monAspect);
ulong number = 30;
Console.WriteLine("Computing {0}. fibonacci number.", number);
// monitoring aspect calculates the time of execution
// and display on the console
ulong result = lib.Fibonacci(number);
Console.WriteLine("Result is {0}.", result);
Console.Read();
}
}
public class MathLibrary
{
public virtual ulong Fibonacci(ulong a)
{
return calcFibonacci(a);
}
// private methods - not matched
private ulong calcFibonacci(ulong a)
{
if (a > 40)
throw new ApplicationException("Error: Can only compute the first 40 fibonacci numbers.");
if (a <= 2)
return 1;
else
return (calcFibonacci(a - 1) + calcFibonacci(a - 2));
}
}
public class MonitoringAspect : Aspect
{
[IncludeAll]
[Call(Advice.Before)]
public void Start_Monitor([JPContext] Context context, params object[] args)
{
Stopwatch sw = new Stopwatch();
sw.Start();
context.Tag = sw;
}
[IncludeAll]
[Call(Advice.After)]
public void Stop_Monitor([JPContext] Context context, params object[] args)
{
Stopwatch sw = (Stopwatch)context.Tag;
sw.Stop();
Console.WriteLine("{0} done in {1}ms.", context.CurrentMethod.Name, sw.ElapsedMilliseconds);
}
}
}
LOOM.NET 主页
var hideSidebar = true;
下面的示例代码演示了如何使用 Rapier-LOOM.NET 来监视一个方法的运行时间
using System;
using System.Collections.Generic;
using System.Text;
using Loom;
using Loom.JoinPoints;
namespace Monitoring
{
class Program
{
static void Main(string[] args)
{
MonitoringAspect monAspect = new MonitoringAspect();
// interweave with the monitoring aspect
MathLibrary lib = Weaver.Create<MathLibrary>(monAspect);
ulong number = 30;
Console.WriteLine("Computing {0}. fibonacci number.", number);
// monitoring aspect calculates the time of execution
// and display on the console
ulong result = lib.Fibonacci(number);
Console.WriteLine("Result is {0}.", result);
Console.Read();
}
}
public class MathLibrary
{
public virtual ulong Fibonacci(ulong a)
{
return calcFibonacci(a);
}
// private methods - not matched
private ulong calcFibonacci(ulong a)
{
if (a > 40)
throw new ApplicationException("Error: Can only compute the first 40 fibonacci numbers.");
if (a <= 2)
return 1;
else
return (calcFibonacci(a - 1) + calcFibonacci(a - 2));
}
}
public class MonitoringAspect : Aspect
{
[IncludeAll]
[Call(Advice.Before)]
public void Start_Monitor([JPContext] Context context, params object[] args)
{
Stopwatch sw = new Stopwatch();
sw.Start();
context.Tag = sw;
}
[IncludeAll]
[Call(Advice.After)]
public void Stop_Monitor([JPContext] Context context, params object[] args)
{
Stopwatch sw = (Stopwatch)context.Tag;
sw.Stop();
Console.WriteLine("{0} done in {1}ms.", context.CurrentMethod.Name, sw.ElapsedMilliseconds);
}
}
}
LOOM.NET 主页
var hideSidebar = true;
相关文章推荐
- How to release an unmanaged library loaded into managed .NET code
- Exploring refit, an automatic type-safe REST library for .NET Standard
- An FTP client library for .NET 2.0
- AOP的一些概念和LOOM.NET
- Leveraging .NET Components and IDE Integration: UI AOP in an MVC use case By Daniel Cazzulino [XML MVP]
- Securing an ASP.Net application...
- A project with an Output Type of Class Library cannot be started directly的解决
- An incompatible version 1.1.14 of APR based Apache Tomcat Native library is installed, while Tomcat
- An older version 1.1.14 of the APR based Apache Tomcat Native library is installed
- Using Nini .NET Configuration Library
- 为什么.NET Framework就没有个专门的P/Invoke Library?
- “数据访问函数库”(DataAccessLibrary for .net2.0 )源代码下载 09.06.15更新
- ASP.NET AJAX 4.0 Preview 3 (Part 1 - ADO.NET Data Service Client Library)
- Spring.Net AOP实例
- 从抽象谈起(三):AOP编程和ASP.NET MVC
- Spring.Net 面向切面AOP
- Using the Enterprise Library Validation Application Block in ASP.NET - Part II
- VintaSoftBarcode.NET Library 条形码识别控件
- SSIS Passing Parameters to an ADO .NET Source query;向ado.net数据源传递参数。