Questions tagged [aop]

AOP stands for Aspect-Oriented Programming. Use this tag if your question is about aspect-oriented concepts and techniques, or for programming problems using AOP extensions in any language. AOP increases modularity by allowing the separation of "cross-cutting concerns" into aspects. Click learn more... to find out what it's all about.

AOP stands for aspect-oriented programming. Questions about aspect-oriented concepts, techniques, and programming problems using AOP extensions in any language should have this tag.

AOP exists because there are two types of requirements in software engineering: functional requirements (concerns) describe specific behaviors; non-functional requirements (cross-cutting concerns) describe general qualities or services. In OOP, concerns are implemented in a very modular way -- all of the code for a concern is kept together, usually in a class. This is a good thing because modular code increases software quality.

However, cross-cutting concerns cannot be modularized in OOP (that's why they're called "cross-cutting" because they 'cut across' the functional concerns). Code for a cross-cutting concern ends up being spread out (tangled) over many, or even all, of the modules in an OOP program. AOP fixes this problem by collecting that spread-out code into one module called an aspect.

Logging, caching, security, and transaction management are examples of cross-cutting concerns. AOP makes it straightforward to retrofit existing applications with any of these services. The original code is not modified. Instead, an aspect is created with advice and pointcuts. Advice is like a class method - it contains code with the new functionality to be added. A pointcut is code that selects one or more join points. Join points are specific places in the existing program where the advice will be applied. The new program is created during a process called weaving, when the original code and the aspect code are integrated with each other. Weaving can be done at compile-time or load-time, so you can add aspects to programs even when you don't have the source code (there are some restrictions, see here for example).

The most widely used AOP language is AspectJ, which is an aspect-oriented enhancement to Java. Using AOP in the Spring framework is also popular here on SO. AOP is accessible in a number of ways including command-line, Eclipse, Spring, and IntelliJ Ultimate. AOP is also available for several other languages: Python, JavaScript, Ruby, Lua, and Smalltalk.

AOP was first used in 1997 at Xerox PARC to solve the problem of tangled cross-cutting concerns in object-oriented programs.

AOP-related SO Tags:

3657 questions
16
votes
3 answers

Handling record/entity level security in an ASP.NET MVC application

What is everyone doing to handle security (retrieval and modification) of individual records in an ASP.NET MVC application? This application has a Service/Business layer and a Data Access layer that are completely separate from the Web user…
Sigray
  • 239
  • 4
  • 10
16
votes
5 answers

Spring's LoadTimeWeaver Agent not starting up

I'm attempting to implement Load time weaving using Spring and AspectJ. To the best of my knowledge I have everything configured properly but I keep getting the error when I try to run my integration…
Conner McNamara
  • 365
  • 1
  • 5
  • 15
16
votes
6 answers

Audit Java: system to detect exceptions thrown / caught (aop?)

Due to checked exceptions, we can have some problems in production having all exceptions caught in the right place and logged correctly. I wonder if there is some opensource tool to help with auditing these problems. For example, is there some AOP…
Sebastien Lorber
  • 89,644
  • 67
  • 288
  • 419
16
votes
5 answers

What is Aspect Oriented Programming?

Duplicate: What is aspect-oriented programming? Every time I here a podcast or read a blog entry about it, even here, they make it sound like string theory or something. Is the best way to describe it OOP with Dependency Injection on…
Charles Graham
  • 24,293
  • 14
  • 43
  • 56
16
votes
1 answer

Spring Boot Logger Aspects

I'm having problems getting my logging aspect to log information when methods from classes of a particular package are accessed. In other words, "no" logging occurs. I even got desperate and added System.out.println statements, with no luck. All…
Rick
  • 699
  • 1
  • 6
  • 17
16
votes
3 answers

Mono Cecil vs. PostSharp Core vs. Microsoft CCI for implementing AOP framework

Which is the better in terms of capabilities, easy of use, documentation, samples, community/support, VS integration, known implementations, long-term viability, and build speed to implement a custom AOP framework? I'll start with what I know (I…
user65199
15
votes
2 answers

Calling @Transactional method from non-transactional method in Spring 4.3

I have the following code: @Service public class ItemService { ... public void addItems(@Nonnull DocumentDTO dto) throws Exception { // some code that takes some time to process ... addItems(dto.getDocId(), items); …
serg kunz
  • 505
  • 1
  • 4
  • 9
15
votes
3 answers

Interceptor with Microsoft.Extensions.DependencyInjection and asp.net web api 2 for cross cutting concerns like logging

We are using Microsoft.Extensions.DependencyInjection in our asp.net web api2 for dependency injection. For cross cutting concerns like logging, we are of thought that aspect oriented programming should be considered and unable to find any support…
15
votes
2 answers

Difference between @target and @within (Spring AOP)

Spring manual says: any join point (method execution only in Spring AOP) where the target object has an @Transactional annotation: @target(org.springframework.transaction.annotation .Transactional) any join point (method execution only in…
Steve Romanchuk
  • 153
  • 1
  • 1
  • 4
15
votes
3 answers

Cool PostSharp aspects

I'm looking for interesting PostSharp aspects - anything that you found useful and wouldn't mind sharing.
Dmitri Nesteruk
  • 23,067
  • 22
  • 97
  • 166
15
votes
1 answer

Structuremap interception for registry scanned types

I have a ASP MVC 4 app that uses Structuremap. I'm trying to add logging to my application via Structuremap interception. In a Registry, I scan a specific assembly in order to register all of it's types with the default convention: public class…
rinat
  • 167
  • 1
  • 1
  • 7
15
votes
1 answer

Spring Expression Language in custom annotation

I want to use Spring Expression Language in a custom Annotation. This annotation will be consumed by a custom Aspect. Check this out: @StatisticEventTrigger(value = TestStatisticEvent.class, expression = "#p1") public void someOtherMethod(String…
goosefraba
  • 241
  • 1
  • 3
  • 10
14
votes
7 answers

Javascript function hooks

EDIT: OK, I believe the following solutions are valid: Use the jQuery AOP plugin. It basically wraps the old function together with the hook into a function sandwich and reassigns it to the old function name. This causes nesting of functions with…
Seyen
  • 143
  • 1
  • 1
  • 6
14
votes
2 answers

Ninject Intercept any method with certain attribute?

How can I get Ninject.Extensions.Interception to basically let me bind a specific interceptor to any method that has an attribute... psudocode: Kernel.Intercept(context => context.Binding.HasAttribute()) …
somemvcperson
  • 1,263
  • 2
  • 18
  • 31
14
votes
7 answers

Unit Testing and PostSharp

I'm wondering what the best way to do this is... I'm interested in introducing PostSharp into one of my projects, but I'm not sure how to unit test classes marked with an attribute properly. For example: public class hello { …
Alex
  • 141
  • 3