All Projects → ezequieljuliano → Aspect4Delphi

ezequieljuliano / Aspect4Delphi

Licence: Apache-2.0 License
Concepts of aspect-oriented programming (AOP) in Delphi.

Programming Languages

pascal
1382 projects
Batchfile
5799 projects

Projects that are alternatives of or similar to Aspect4Delphi

AspecTS
An aspect-oriented programming library implemented in TypeScript
Stars: ✭ 21 (-25%)
Mutual labels:  aop, aspect-oriented-programming, aspects
kaop
Advanced OOP Library with createClass, inheritance, providers, injectors, advices which enables handy Inversion of Control techniques
Stars: ✭ 40 (+42.86%)
Mutual labels:  aspect-oriented-programming, aop-architecture
NCop
Composite-aspect oriented framework for .NET
Stars: ✭ 30 (+7.14%)
Mutual labels:  aop, aspect-oriented-programming
goaop-laravel-bridge
Integration bridge for Go! AOP framework and Laravel
Stars: ✭ 91 (+225%)
Mutual labels:  aop, aspect-oriented-programming
Agentframework
An elegant & efficient TypeScript metaprogramming API to build software agents
Stars: ✭ 97 (+246.43%)
Mutual labels:  interceptor, aop
Framework
💎 Go! AOP PHP - modern aspect-oriented framework for the new level of software development
Stars: ✭ 1,559 (+5467.86%)
Mutual labels:  interceptor, aop
Cauldron
C# Toolkit
Stars: ✭ 68 (+142.86%)
Mutual labels:  interceptor, aop
T Mvp
Android AOP Architecture by Apt, AspectJ, Javassisit, based on Realm+Databinding+MVP+Retrofit+Rxjava2
Stars: ✭ 2,740 (+9685.71%)
Mutual labels:  aop, aop-architecture
aspectgo
Aspect-Oriented Programming framework for Go
Stars: ✭ 62 (+121.43%)
Mutual labels:  aop, aspect-oriented-programming
CNeptune
CNeptune improve productivity & efficiency by urbanize .net module with meta-code to lay foundation for frameworks
Stars: ✭ 30 (+7.14%)
Mutual labels:  aop, aspect-oriented-programming
Ray.aop
An aspect-oriented framework for PHP
Stars: ✭ 67 (+139.29%)
Mutual labels:  interceptor, aop
KYHooker
A library for complex aspect oriented programming
Stars: ✭ 38 (+35.71%)
Mutual labels:  aspect-oriented-programming, aspects
Cauldron
C# Toolkit
Stars: ✭ 27 (-3.57%)
Mutual labels:  interceptor, aop
controller-logger
AOP based API logging for Spring Boot
Stars: ✭ 57 (+103.57%)
Mutual labels:  aop, aspects
Blockhook
Hook Objective-C blocks. A powerful AOP tool.
Stars: ✭ 742 (+2550%)
Mutual labels:  interceptor, aop
Asmin
Asmin is .NET CORE project infrastructure, to get a quick start on the project.
Stars: ✭ 89 (+217.86%)
Mutual labels:  interceptor, aspect-oriented-programming
Decor.NET
A simple way to decorate a class with additional functionality using attributes.
Stars: ✭ 29 (+3.57%)
Mutual labels:  aop, aspect-oriented-programming
Mimick.Fody
An integrated framework for dependency injection and aspect-oriented processing.
Stars: ✭ 15 (-46.43%)
Mutual labels:  aop, aspect-oriented-programming
DotNETCarRental
Daily car rental simulation with ASP.NET.
Stars: ✭ 13 (-53.57%)
Mutual labels:  interceptor, aspect-oriented-programming
fastaop
🚀 lightweight, high-performance AOP framework based on Java Annotation Processing, similar to Lombok
Stars: ✭ 87 (+210.71%)
Mutual labels:  aop

Aspect For Delphi

The Aspect4Delphi consists of an library that enables the use of the concept of aspect-oriented programming (AOP) in Delphi.

About The Project

AOP is a programming paradigm that aims to increase modularity by allowing the separation of cross-cutting concerns. It does so by adding additional behavior to existing code without modification of the code itself. Instead, we can declare this new code and these new behaviors separately.

Aspect4Delphi helps us implement these cross-cutting concerns.

Types of Advice

  • Before advice: advice that executes before a join point, but which does not have the ability to prevent execution flow proceeding to the join point (unless it throws an exception).
  • After advice: advice to be executed after a join point completes normally: for example, if a method returns without throwing an exception.
  • Exception advice: Advice to be executed if a method exits by throwing an exception.

Built With

Getting Started

To get a local copy up and running follow these simple steps.

Prerequisites

To use this library an updated version of Delphi IDE (XE or higher) is required.

Installation

Clone the repo

git clone https://github.com/ezequieljuliano/Aspect4Delphi.git

Add the "Search Path" of your IDE or your project the following directories:

Aspect4Delphi\src

Usage

To provide the aspect orientation paradigm in your project with Aspect4Delphi you need:

  • Implement a pointcut attribute.
  • Implement a class that represents your aspect.
  • Register your pointcut attribute and its aspect class in context.
  • Set your classes methods to virtual.
  • Write down your methods with the respective aspect.

Sample

To illustrate usage let's look at a solution for managing logs of an application.

Implement a pointcut attribute (preferably inherits from AspectAttribute):

interface

uses

  Aspect.Core;

type

  LoggingAttribute = class(AspectAttribute)
  private
    { private declarations }
  protected
    { protected declarations }
  public
    { public declarations }
  end;

implementation

end.

Implement the class that represents your aspect and contains the advices methods (you must implement the IAspect interface):

interface

uses

  System.SysUtils,
  System.Rtti,
  Aspect,
  Aspect.Core,
  Logging.Attribute,
  App.Context;

type

  ELoggingAspectException = class(Exception)
  private
    { private declarations }
  protected
    { protected declarations }
  public
    { public declarations }
  end;

  TLoggingAspect = class(TAspectObject, IAspect)
  private
    { private declarations }
  protected
    procedure OnBefore(
      instance: TObject;
      method: TRttiMethod;
      const args: TArray<TValue>;
      out invoke: Boolean;
      out result: TValue
      ); override;

    procedure OnAfter(
      instance: TObject;
      method: TRttiMethod;
      const args: TArray<TValue>;
      var result: TValue
      ); override;

    procedure OnException(
      instance: TObject;
      method: TRttiMethod;
      const args: TArray<TValue>;
      out raiseException: Boolean;
      theException: Exception;
      out result: TValue
      ); override;
  public
    { public declarations }
  end;

implementation

{ TLoggingAspect }

procedure TLoggingAspect.OnAfter(instance: TObject; method: TRttiMethod;
  const args: TArray<TValue>; var result: TValue);
var
  attribute: TCustomAttribute;
begin
  inherited;
  for attribute in method.GetAttributes do
    if attribute is LoggingAttribute then
    begin
      LoggingFile.Add('After the execution of ' + 
		instance.QualifiedClassName + ' - ' + 
		method.Name
	  );
      Break;
    end;
end;

procedure TLoggingAspect.OnBefore(instance: TObject; method: TRttiMethod;
  const args: TArray<TValue>; out invoke: Boolean; out result: TValue);
var
  attribute: TCustomAttribute;
begin
  inherited;
  for attribute in method.GetAttributes do
    if attribute is LoggingAttribute then
    begin
      LoggingFile.Add('Before the execution of ' + 
		instance.QualifiedClassName + ' - ' + 
		method.Name
	  );
      Break;
    end;
end;

procedure TLoggingAspect.OnException(instance: TObject; method: TRttiMethod;
  const args: TArray<TValue>; out raiseException: Boolean;
  theException: Exception; out result: TValue);
var
  attribute: TCustomAttribute;
begin
  inherited;
  for attribute in method.GetAttributes do
    if attribute is LoggingAttribute then
    begin
      LoggingFile.Add('Exception in executing ' + 
		instance.QualifiedClassName + ' - ' + 
		method.Name + ' - ' + 
		theException.Message
	  );
      Break;
    end;
end;

end.

Register your pointcut attribute and its aspect class in context (preferably keep this context in singleton instance):

interface

uses

  Logging.Aspect;
  Aspect.Context;  
  
function AspectContext: IAspectContext;

implementation

var

  AspectContextInstance: IAspectContext = nil;
  
function AspectContext: IAspectContext;
begin
  if (AspectContextInstance = nil) then
  begin
    AspectContextInstance := TAspectContext.Create;
    AspectContextInstance.RegisterAspect(TLoggingAspect.Create);
  end;
  Result := AspectContextInstance;
end;

end.

In your business rule class use the attribute to define your joins points. You can use the constructor and destructor to add your class at the Weaver.

interface

uses

  System.SysUtils,
  Logging.Attribute,
  App.Context;

type

  EWhatsAppMessageException = class(Exception)
  private
    { private declarations }
  protected
    { protected declarations }
  public
    { public declarations }
  end;

  TWhatsAppMessage = class
  private
    { private declarations }
  protected
    { protected declarations }
  public
    constructor Create;
    destructor Destroy; override;

    [Logging]
    procedure Send; virtual;
  end;

implementation

{ TWhatsAppMessage }

constructor TWhatsAppMessage.Create;
begin
  inherited Create;
  AspectContext.Weaver.Proxify(Self);
end;

destructor TWhatsAppMessage.Destroy;
begin
  AspectContext.Weaver.Unproxify(Self);
  inherited Destroy;
end;

procedure TWhatsAppMessage.Send;
begin
  //Execution of send.
end;

Roadmap

See the open issues for a list of proposed features (and known issues).

Contributing

Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Distributed under the APACHE LICENSE. See LICENSE for more information.

Contact

To contact us use the options:

Project Link

https://github.com/ezequieljuliano/Aspect4Delphi

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].