SlideShare a Scribd company logo
Introduction to Aspect-Oriented-Programming
AOP in C# 2013
TOPICS

 -   What is bad and good design ?
 -   Problem statement.
 -   What is AOP ?
 -   Demo
WHAT IS BAD DESIGN ?
WHAT IS BAD DESIGN ?

-the system is rigid: it's hard to change a part of the system
without affecting too many other parts of the system

-the system is fragile: when making a change, unexpected
parts of the system break

- the system or component is immobile: it is hard to reuse it in
another application because it cannot be disentangled from
the current application
AOP in C# 2013
AOP in C# 2013
AOP in C# 2013
class GarbageService
{
     public void Transfer(int sourceID, int destinationID, int size)
     {
         Storage source = Storage.GetById(sourceID);
         Storage destination = Storage.GetById(destinationID);

        var garbage = source.GetGarbage(size);
        destination.PutGarbage(garbage);
    }
}
class GarbageService
{
     public void Transfer(int sourceID, int destinationID, int size)
     {
            Trace.TraceInformation("Entering GarbageService.Transfer(
                sourceID={0},destinationID={1})", sourceID, destinationID);

           try
           {
                 Storage source = Storage.GetById(sourceID);
                 Storage destination = Storage.GetById(destinationID);

                 var garbage = source.GetGarbage(size);
                 destination.PutGarbage(garbage);
           }
           catch (Exception ex)
           {
               Trace.TraceError("Exception: GarbageService.Transfer(
               sourceID = {0}, destinationID = {1}) failed : {2}“,
                                sourceID, destinationID, ex.Message);
               throw;
           }
    }
}
class GarbageService
{
        public void Transfer(int sourceID, int destinationID, int size)
        {
            Trace.TraceInformation("Entering GarbageService.Transfer(sourceID = {0}, destinationID =
                                     {1})", sourceID, destinationID);

           if (sourceID <= 0)
           {
               throw new ArgumentOutOfRangeException("sourceID");
           }
           if (destinationID <= 0)
           {
               throw new ArgumentOutOfRangeException("destinationID");
           }
           if (size <= 0)
           {
               throw new ArgumentOutOfRangeException("size");
           }

           try
           {
                 Storage source = Storage.GetById(sourceID);
                 Storage destination = Storage.GetById(destinationID);

                 var garbage = source.GetGarbage(size);
                 destination.PutGarbage(garbage);
           }
           catch (Exception ex)
           {
               Trace.TraceError("Exception: GarbageService.Transfer(sourceID = {0}, destinationID = {1})
                                 failed : {2}“, sourceID, destinationID, ex.Message);
               throw;
           }
       }
}
REQUIREMENTS
• Functional Requirements
    • Line-of-business




• Non functional requirements
    • Logging
    • Caching
    • Transaction
    • Validation
    • Exception Handling
    • Thread Sync
    • GUI Binding
    • … and a lot more!
WHAT IS AOP ?
AOP - is a programming paradigm which aims to increase modularity by allowing the
       separation of cross-cutting concerns.


AOP - an approach that extends OOP and addresses the issue of cross-cutting
      concerns:
        • Encapsulate cross-cutting concerns into Aspects.
        • Improves code reusability, modularity and separation of concerns.
        • Reduces defects by reducing boiler – plate code.


With AOP, you still define the common functionality in one
place, but you can declaratively define how and where this
functionality is applied without having
to modify the class to which you are applying the new
feature.
AOP
• doesn’t solve any new problem
• it’s just another tool in your toolbox
• the main goal is nice separation of concerns
• a decrease in development costs and software
delivery time;
• an increase in application maintainability.
• reduce noise in source == more clean model
AOP TERMINOLOGY
• Join Point
   • place where behavior can be added
• Advice
   • code that can be injected at join points
• Point Cut
   • join points where advices should be applied
AOP in C# 2013
AOP in C# 2013
AOP in C# 2013
AOP in C# 2013
AOP WEAVING
• Compile time weaving
   • Source-Level Weaving
   • Modifying the MSIL code

• Run-Time weaving
   • Dynamic Proxy
PostSharp                               is the most

                comprehensive aspect-oriented framework for .NET



Gael Fraiteur
Demo
AOP in C# 2013
Philip Laureano
   Comparing Aspect Frameworks
      STATIC VS DYNAMIC AOP
                                       Spring.NET
PostSharp                 LinFu        Castle
                                       MS Unity/PIAB




Build-Time:               Hybrid       Run-Time:
Very Expressive                        Less Expressive
Robust Model                           Brittle Model
Not Invasive                           Invasive
Static                                 Dynamic
   Comparing Aspect Frameworks
EXPRESSIVENESS
What can you do with the framework?

                                          Spring.NET
                      PostSharp   Linfu                Unity/PIAB
                                            Castle
Method Interception      Yes      Yes        Yes          Yes
Private/Sealed
                         Yes      Yes
Member Interception
Event Interception       Yes
Member Introduction      Yes
AOP in C# 2013
We need Aspects!
We have
great frameworks!

More Related Content

PDF
Advice weaving in AspectJ
KEY
Spring AOP
PPTX
CDO Ignite
PDF
RMI and CORBA Why both are valuable tools
ODP
CORBA & RMI in java
PDF
Writing usableap isinpractice
PPT
Corba by Example
Advice weaving in AspectJ
Spring AOP
CDO Ignite
RMI and CORBA Why both are valuable tools
CORBA & RMI in java
Writing usableap isinpractice
Corba by Example

What's hot (20)

PDF
Distributed Objects: CORBA/Java RMI
PPTX
Corba model ppt
PPTX
Common Object Request Broker Architecture
PDF
Intel open mp
PPT
Chapter 17 corba
PDF
Api and Fluency
PPT
Lecture4 corba
PPT
PPTX
Sc11 presentation 2001_06_28
PDF
Adapter 2pp
PDF
50+ java interview questions
PPTX
Corba in power system
PPT
CORBA Basic and Deployment of CORBA
PDF
CORBA - Introduction and Details
PPT
Apache Harmony: An Open Innovation
PPT
Unit iv
PPT
Java interview-questions-and-answers
PDF
PPTX
Corba concepts & corba architecture
PPTX
Massively Scalable Applications - TechFerry
Distributed Objects: CORBA/Java RMI
Corba model ppt
Common Object Request Broker Architecture
Intel open mp
Chapter 17 corba
Api and Fluency
Lecture4 corba
Sc11 presentation 2001_06_28
Adapter 2pp
50+ java interview questions
Corba in power system
CORBA Basic and Deployment of CORBA
CORBA - Introduction and Details
Apache Harmony: An Open Innovation
Unit iv
Java interview-questions-and-answers
Corba concepts & corba architecture
Massively Scalable Applications - TechFerry
Ad

Similar to AOP in C# 2013 (20)

PPTX
Introduction to Aspect Oriented Programming in .NET with PostSharp by Zubair ...
PPTX
Introduction to aop
PPTX
Architecting C Sharp for Cross Cutting Concerns
PPTX
Introduction to Aspect Oriented Programming (DDD South West 4.0)
PPTX
Produce Cleaner Code with Aspect-Oriented Programming
PPTX
06.1 .Net memory management
PDF
Clean Code at Silicon Valley Code Camp 2011 (02/17/2012)
PPTX
Clean Code for East Bay .NET User Group
PPTX
Il 09 T3 William Spreitzer
PPTX
Aspect oriented programming
PDF
Smart Client Development
PDF
10 Ways To Improve Your Code
PDF
C# .NET Developer Portfolio
PPTX
Intro To AOP
PDF
AOP in NET Practical Aspect Oriented Programming Matthew D. Groves
PDF
Contract First Development with Microsoft Code Contracts and Microsoft Pex at...
PPTX
Common ASP.NET Design Patterns - Telerik India DevCon 2013
PPTX
Introduction to Aspect Oriented Programming by Donald Belcham
PPTX
Introduction To AOP
PPTX
Clean Code - Design Patterns and Best Practices for Bay.NET SF User Group (01...
Introduction to Aspect Oriented Programming in .NET with PostSharp by Zubair ...
Introduction to aop
Architecting C Sharp for Cross Cutting Concerns
Introduction to Aspect Oriented Programming (DDD South West 4.0)
Produce Cleaner Code with Aspect-Oriented Programming
06.1 .Net memory management
Clean Code at Silicon Valley Code Camp 2011 (02/17/2012)
Clean Code for East Bay .NET User Group
Il 09 T3 William Spreitzer
Aspect oriented programming
Smart Client Development
10 Ways To Improve Your Code
C# .NET Developer Portfolio
Intro To AOP
AOP in NET Practical Aspect Oriented Programming Matthew D. Groves
Contract First Development with Microsoft Code Contracts and Microsoft Pex at...
Common ASP.NET Design Patterns - Telerik India DevCon 2013
Introduction to Aspect Oriented Programming by Donald Belcham
Introduction To AOP
Clean Code - Design Patterns and Best Practices for Bay.NET SF User Group (01...
Ad

Recently uploaded (20)

PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
A comparative analysis of optical character recognition models for extracting...
PPTX
TLE Review Electricity (Electricity).pptx
PDF
Zenith AI: Advanced Artificial Intelligence
PDF
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
PDF
Heart disease approach using modified random forest and particle swarm optimi...
PPTX
OMC Textile Division Presentation 2021.pptx
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PPTX
Tartificialntelligence_presentation.pptx
PDF
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
A comparative study of natural language inference in Swahili using monolingua...
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Accuracy of neural networks in brain wave diagnosis of schizophrenia
PDF
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
PDF
August Patch Tuesday
PDF
Enhancing emotion recognition model for a student engagement use case through...
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
A comparative analysis of optical character recognition models for extracting...
TLE Review Electricity (Electricity).pptx
Zenith AI: Advanced Artificial Intelligence
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
Heart disease approach using modified random forest and particle swarm optimi...
OMC Textile Division Presentation 2021.pptx
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Tartificialntelligence_presentation.pptx
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
Assigned Numbers - 2025 - Bluetooth® Document
Encapsulation_ Review paper, used for researhc scholars
Agricultural_Statistics_at_a_Glance_2022_0.pdf
A comparative study of natural language inference in Swahili using monolingua...
Programs and apps: productivity, graphics, security and other tools
Unlocking AI with Model Context Protocol (MCP)
Accuracy of neural networks in brain wave diagnosis of schizophrenia
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
August Patch Tuesday
Enhancing emotion recognition model for a student engagement use case through...

AOP in C# 2013

  • 3. TOPICS - What is bad and good design ? - Problem statement. - What is AOP ? - Demo
  • 4. WHAT IS BAD DESIGN ?
  • 5. WHAT IS BAD DESIGN ? -the system is rigid: it's hard to change a part of the system without affecting too many other parts of the system -the system is fragile: when making a change, unexpected parts of the system break - the system or component is immobile: it is hard to reuse it in another application because it cannot be disentangled from the current application
  • 9. class GarbageService { public void Transfer(int sourceID, int destinationID, int size) { Storage source = Storage.GetById(sourceID); Storage destination = Storage.GetById(destinationID); var garbage = source.GetGarbage(size); destination.PutGarbage(garbage); } }
  • 10. class GarbageService { public void Transfer(int sourceID, int destinationID, int size) { Trace.TraceInformation("Entering GarbageService.Transfer( sourceID={0},destinationID={1})", sourceID, destinationID); try { Storage source = Storage.GetById(sourceID); Storage destination = Storage.GetById(destinationID); var garbage = source.GetGarbage(size); destination.PutGarbage(garbage); } catch (Exception ex) { Trace.TraceError("Exception: GarbageService.Transfer( sourceID = {0}, destinationID = {1}) failed : {2}“, sourceID, destinationID, ex.Message); throw; } } }
  • 11. class GarbageService { public void Transfer(int sourceID, int destinationID, int size) { Trace.TraceInformation("Entering GarbageService.Transfer(sourceID = {0}, destinationID = {1})", sourceID, destinationID); if (sourceID <= 0) { throw new ArgumentOutOfRangeException("sourceID"); } if (destinationID <= 0) { throw new ArgumentOutOfRangeException("destinationID"); } if (size <= 0) { throw new ArgumentOutOfRangeException("size"); } try { Storage source = Storage.GetById(sourceID); Storage destination = Storage.GetById(destinationID); var garbage = source.GetGarbage(size); destination.PutGarbage(garbage); } catch (Exception ex) { Trace.TraceError("Exception: GarbageService.Transfer(sourceID = {0}, destinationID = {1}) failed : {2}“, sourceID, destinationID, ex.Message); throw; } } }
  • 12. REQUIREMENTS • Functional Requirements • Line-of-business • Non functional requirements • Logging • Caching • Transaction • Validation • Exception Handling • Thread Sync • GUI Binding • … and a lot more!
  • 13. WHAT IS AOP ? AOP - is a programming paradigm which aims to increase modularity by allowing the separation of cross-cutting concerns. AOP - an approach that extends OOP and addresses the issue of cross-cutting concerns: • Encapsulate cross-cutting concerns into Aspects. • Improves code reusability, modularity and separation of concerns. • Reduces defects by reducing boiler – plate code. With AOP, you still define the common functionality in one place, but you can declaratively define how and where this functionality is applied without having to modify the class to which you are applying the new feature.
  • 14. AOP • doesn’t solve any new problem • it’s just another tool in your toolbox • the main goal is nice separation of concerns • a decrease in development costs and software delivery time; • an increase in application maintainability. • reduce noise in source == more clean model
  • 15. AOP TERMINOLOGY • Join Point • place where behavior can be added • Advice • code that can be injected at join points • Point Cut • join points where advices should be applied
  • 20. AOP WEAVING • Compile time weaving • Source-Level Weaving • Modifying the MSIL code • Run-Time weaving • Dynamic Proxy
  • 21. PostSharp is the most comprehensive aspect-oriented framework for .NET Gael Fraiteur
  • 22. Demo
  • 25. Comparing Aspect Frameworks STATIC VS DYNAMIC AOP Spring.NET PostSharp LinFu Castle MS Unity/PIAB Build-Time: Hybrid Run-Time: Very Expressive Less Expressive Robust Model Brittle Model Not Invasive Invasive Static Dynamic
  • 26. Comparing Aspect Frameworks EXPRESSIVENESS What can you do with the framework? Spring.NET PostSharp Linfu Unity/PIAB Castle Method Interception Yes Yes Yes Yes Private/Sealed Yes Yes Member Interception Event Interception Yes Member Introduction Yes