SlideShare ist ein Scribd-Unternehmen logo
1 von 42
Downloaden Sie, um offline zu lesen
AOP mit .NET



12.04.2012
Dipl.-Inf. (FH) Johannes Hoppe
Johannes Hoppe
ASP.NET MVC Webentwickler
  www.johanneshoppe.de
01
Architektur und Patterns
Patterns
software craftsmanship
Business Code



public class CustomerProcesses
{
    public void RentBook( int bookId, int customerId )
    {
        Book book = Book.GetById( bookId );
        Customer customer = Customer.GetById( customerId );

         book.RentedTo = customer;
         customer.AccountLines.Add(
          string.Format( "Rental of book {0}.", book ), book.RentalPrice
);
         customer.Balance -= book.RentalPrice;
     }
}
Business Code
Business Code



public class CustomerProcesses
{
    public void RentBook( int bookId, int customerId )
    {
        Book book = Book.GetById( bookId );
        Customer customer = Customer.GetById( customerId );

         book.RentedTo = customer;
         customer.AccountLines.Add(
          string.Format( "Rental of book {0}.", book ), book.RentalPrice
);
         customer.Balance -= book.RentalPrice;
     }
}
Business Code
+ Logging
                internal class CustomerProcesses
                {
                    private static readonly TraceSource trace =
                        new TraceSource( typeof (CustomerProcesses).FullName );

                        public void RentBook( int bookId, int customerId )
                        {
                           trace.TraceInformation(
                                "Entering CustomerProcesses.CreateCustomer( bookId = {0},
                                 customerId = {1} )",
                                bookId, customerId );
                           try
                           {
                                Book book = Book.GetById( bookId );
                                Customer customer = Customer.GetById( customerId );

                                book.RentedTo = customer;
                                customer.AccountLines.Add(
                                    string.Format( "Rental of book {0}.", book ), book.RentalPrice );
                                customer.Balance -= book.RentalPrice;

                                trace.TraceInformation(
                                  "Leaving CustomerProcesses.CreateCustomer( bookId = {0}, customerId = {1} )",
                                  bookId, customerId );
                            }
                            catch ( Exception e )
                            {
                                trace.TraceEvent( TraceEventType.Error, 0,
                                                  "Exception: CustomerProcesses.CreateCustomer(
                                                  bookId = {0}, customerId = {1} ) failed : {2}",
                                                  bookId, customerId, e.Message );
                                 throw;
                            }
                    }
                }
Business Code
+ Logging
                   internal class CustomerProcesses

+ Vorbedingungen   {
                       private static readonly TraceSource trace =
                           new TraceSource(typeof(CustomerProcesses).FullName);

                       public void RentBook(int bookId, int customerId)
                       {
                           if (bookId <= 0) throw new ArgumentOutOfRangeException("bookId");
                           if (customerId <= 0) throw new ArgumentOutOfRangeException("customerId");

                           trace.TraceInformation(
                               "Entering CustomerProcesses.CreateCustomer( bookId = {0}, customerId = {1} )",
                               bookId, customerId);

                           try
                           {
                                 Book book = Book.GetById(bookId);
                                 Customer customer = Customer.GetById(customerId);

                                 book.RentedTo = customer;
                                 customer.AccountLines.Add(string.Format("Rental of book {0}.", book),
                                                           book.RentalPrice);
                                 customer.Balance -= book.RentalPrice;

                                 trace.TraceInformation(
                                     "Leaving CustomerProcesses.CreateCustomer( bookId = {0},
                                     customerId = {1} )“, bookId, customerId);
                           }
                           catch (Exception e)
                           {
                               trace.TraceEvent(TraceEventType.Error, 0,
                                      "Exception: CustomerProcesses.CreateCustomer( bookId = {0},
                                       customerId = {1} ) failed : {2}",
                                       bookId, customerId, e.Message);
                               throw;
                           }
                       }
                   }
Business Code
   + Logging        + Transaktionen
   + Vorbedingungen
internal class CustomerProcesses                                                                 ts.Complete();
{                                                                                            }
    private static readonly TraceSource trace =
        new TraceSource(typeof(CustomerProcesses).FullName);                                 break;
                                                                                         }
    public void RentBook(int bookId, int customerId)                                     catch (TransactionConflictException)
    {                                                                                    {
        if (bookId <= 0)                                                                     if (i < 3)
          throw new ArgumentOutOfRangeException("bookId");                                       continue;
        if (customerId <= 0)                                                                 else
          throw new ArgumentOutOfRangeException("customerId");                                   throw;
                                                                                         }
        trace.TraceInformation(                                                      }
            "Entering CustomerProcesses.CreateCustomer( bookId = {0},
            customerId = {1} )“, bookId, customerId);                                trace.TraceInformation(
                                                                                         "Leaving CustomerProcesses.CreateCustomer(
        try                                                                              bookId = {0}, customerId = {1} )",
        {                                                                                bookId, customerId);
              for (int i = 0; ; i++)                                             }
              {                                                                  catch (Exception e)
                  try                                                            {
                  {                                                                  trace.TraceEvent(TraceEventType.Error, 0,
                      using (var ts = new TransactionScope())                          "Exception: CustomerProcesses.CreateCustomer( bookId = {0},
                      {                                                                customerId = {1} ) failed : {2}",
                          Book book = Book.GetById(bookId);                            bookId, customerId, e.Message);
                          Customer customer =                                        throw;
                            Customer.GetById(customerId);                        }
                                                                             }
                         book.RentedTo = customer;
                         customer.AccountLines.Add(                      }
                           string.Format("Rental of book {0}.", book),
                           book.RentalPrice);
                         customer.Balance -= book.RentalPrice;
Business Code
   + Logging        + Transaktionen
   + Vorbedingungen + Exception Handling
internal class CustomerProcesses
{                                                                                                            ts.Complete();
    private static readonly TraceSource trace =                                                          }
        new TraceSource(typeof(CustomerProcesses).FullName);
                                                                                                          break;
    public void RentBook(int bookId, int customerId)                                                  }
    {                                                                                                 catch ( TransactionConflictException )
        if (bookId <= 0) throw new ArgumentOutOfRangeException("bookId");                             {
        if (customerId <= 0)                                                                              if ( i < 3 )
            throw new ArgumentOutOfRangeException("customerId");                                              continue;
                                                                                                          else
        try                                                                                                   throw;
        {                                                                                             }
              trace.TraceInformation(                                                             }
                  "Entering CustomerProcesses.CreateCustomer(
                   bookId = {0}, customerId = {1} )",                                             trace.TraceInformation(
                  bookId, customerId );                                                               "Leaving CustomerProcesses.CreateCustomer(
                                                                                                      bookId = {0}, customerId = {1} )",
              try                                                                                     bookId, customerId );
              {                                                                               }
                    for ( int i = 0;; i++ )                                                   catch ( Exception e )
                    {                                                                         {
                        try                                                                       trace.TraceEvent( TraceEventType.Error, 0,
                        {                                                                          "Exception: CustomerProcesses.CreateCustomer(
                            using ( var ts = new TransactionScope() )                               bookId = {0}, customerId = {1} ) failed : {2}",
                            {                                                                                       bookId, customerId, e.Message );
                                Book book = Book.GetById( bookId );                               throw;
                                Customer customer = Customer.GetById( customerId );           }
                                                                                          }
                               book.RentedTo = customer;                                  catch ( Exception e )
                               customer.AccountLines.Add(                                 {
                                  string.Format( "Rental of book {0}.", book ),               if (ExceptionManager.Handle(e)) throw;
                                  book.RentalPrice );                                     }
                               customer.Balance -= book.RentalPrice;                  }
Business Code
+ Logging        + Transaktionen
+ Vorbedingungen + Exception Handling

+ Feature X
+ Feature Y
+ Feature Z
+…
Kern-            Seperation
funktionalitäten    of Concerns
  (Core Concerns)
VS
VS
    Nicht-
  Funktionale
 Anforderungen
     (Crosscutting Concerns)
Cross-Cutting Concerns


           Security             Data Binding
           Exception Handling   Thread Sync
           Tracing              Caching
           Monitoring           Validation
           Transaction          …
OOP



 OOP
+ AOP
Spring.NET
PostSharp    LinFu    Castle
                      MS Unity




Build-Time   Hybrid   Run-Time
Build-Time: “Statisch”          Run-Time: “Dynamisch”

Erfolgt bei Kompilierung        Erfolgt zur Laufzeit
Code wird direkt verändert      Code bleibt unverändert
Zur Laufzeit keine Änderungen   Zur Laufzeit Änderungen möglich
Auch auf Properties, Felder,    Aufruf wird über Proxy
Events anwendbar                umgeleitet
Keine Interfaces erforderlich   idR. Interfaces erforderlich (Proxy)
02
Live Coding
Logging
LogTimeAspect




          webnoteaop.codeplex.com
Exceptions
ConvertExceptionAspect




                         webnoteaop.codeplex.com
Validierung
ValidationGuardAspect




                        webnoteaop.codeplex.com
Caching
SimpleCacheAspect




           webnoteaop.codeplex.com
03
AOP 1 x 1
AspectJ Begriffe




                   Join Point
                   Pointcut
                   Advice
                   Aspect
AspectJ Begriffe




                   Join Point
                   Pointcut
                   Advice
                   Aspect
IL Code Vorher




         [LogTimeAspect]
         public ActionResult Index()
         {
             IEnumerable<NoteWithCategories> notes =
                 this.WebNoteService.ReadAll();
             return View(notes);
         }
IL Code Nachher

   public ActionResult Index()
   {
       ActionResult CS$1$2__returnValue;
       MethodExecutionArgs CS$0$3__aspectArgs =
           new MethodExecutionArgs(null, null);
       <>z__Aspects.a68.OnEntry(CS$0$3__aspectArgs);
       try
       {
           IEnumerable<NoteWithCategories> notes =
               this.WebNoteService.ReadAll();
           ActionResult CS$1$0000 = base.View(notes);
           CS$1$2__returnValue = CS$1$0000;
       }
       finally
       {
           <>z__Aspects.a68.OnExit(CS$0$3__aspectArgs);
       }
       return CS$1$2__returnValue;
   }
Originale Methode       Aspekt Klasse

                            OnEntry
  try
  {
        Method Body
                            OnSuccess
  }
  catch (Exception e)
  {
                            OnException
  }
  finally
  {
                             OnExit
  }

                        : OnMethodBoundaryAspect
04
Installation
www.sharpcrafters.com/postsharp/download
nuget
http://nuget.org/packages/PostSharp
Spring.NET            PostSharp
springframework.net   sharpcrafters.com


Castle                Demo Download
castleproject.org     webnoteaop.codeplex.com


Unity
unity.codeplex.com
FRAGEN?
Bis bald
›   10.05.2012 – .NET UG Karlsruhe: NoSQL
›   14.05.2012 – .NET Developer Conference (DDC)
                 .Nürnberg: NoSQL
Vielen Dank!
Primitive Aspekt-Typen


›   MethodBoundaryAspect       ›   LocationInterceptionAspect
    › OnEntry                       › OnGetValue
    › OnSuccess                     › OnSetValue
    › OnException
    › OnExit                   ›   EventInterceptionAspect
                                    › OnAddHandler
›   OnExceptionAspect               › OnRemoveHandler
     › OnException                  › OnInvokeHandler

›   MethodInterceptionAspect   ›   MethodImplementationAspect
    › OnInvoke                     › OnInvoke

                               ›   CompositionAspect
                                    › CreateImplementationObject
Bildnachweise
Ausgewählter Ordner © Spectral-Design – Fotolia.com
Warnhinweis-Schild © Sascha Tiebel – Fotolia.com
Liste abhaken © Dirk Schumann – Fotolia.com
3D rendering of an architecture model 2 © Franck Boston – Fotolia.com
Healthcare © ArtmannWitte – Fotolia.com
Stressed businessman © Selecstock – Fotolia.com
Funny cartoon boss © artenot – Fotolia.com

Weitere ähnliche Inhalte

Andere mochten auch

2012-10-12 - NoSQL in .NET - mit Redis und Mongodb
2012-10-12 - NoSQL in .NET - mit Redis und Mongodb2012-10-12 - NoSQL in .NET - mit Redis und Mongodb
2012-10-12 - NoSQL in .NET - mit Redis und Mongodb
Johannes Hoppe
 
Tema 4 conocimiento reproducción humana
Tema 4 conocimiento reproducción humanaTema 4 conocimiento reproducción humana
Tema 4 conocimiento reproducción humana
Ana María Rodriguez
 
El Inicio De La Edad Media
El Inicio De La Edad MediaEl Inicio De La Edad Media
El Inicio De La Edad Media
zhuyibamu
 
Fibromialgia y Sindrome de Fatiga Cronica
Fibromialgia y Sindrome de Fatiga CronicaFibromialgia y Sindrome de Fatiga Cronica
Fibromialgia y Sindrome de Fatiga Cronica
Consultoris Vitae
 
2012-10-16 - WebTechCon 2012: HTML5 & WebGL
2012-10-16 - WebTechCon 2012: HTML5 & WebGL2012-10-16 - WebTechCon 2012: HTML5 & WebGL
2012-10-16 - WebTechCon 2012: HTML5 & WebGL
Johannes Hoppe
 

Andere mochten auch (9)

2012-10-12 - NoSQL in .NET - mit Redis und Mongodb
2012-10-12 - NoSQL in .NET - mit Redis und Mongodb2012-10-12 - NoSQL in .NET - mit Redis und Mongodb
2012-10-12 - NoSQL in .NET - mit Redis und Mongodb
 
2013 02-26 - Software Tests with Mongo db
2013 02-26 - Software Tests with Mongo db2013 02-26 - Software Tests with Mongo db
2013 02-26 - Software Tests with Mongo db
 
2012-09-17 - WDC12: Node.js & MongoDB
2012-09-17 - WDC12: Node.js & MongoDB2012-09-17 - WDC12: Node.js & MongoDB
2012-09-17 - WDC12: Node.js & MongoDB
 
Tema 4 conocimiento reproducción humana
Tema 4 conocimiento reproducción humanaTema 4 conocimiento reproducción humana
Tema 4 conocimiento reproducción humana
 
Modelling Natural Ventilation in IES-VE: Case studies & Research Outlook
Modelling Natural Ventilation in IES-VE: Case studies & Research OutlookModelling Natural Ventilation in IES-VE: Case studies & Research Outlook
Modelling Natural Ventilation in IES-VE: Case studies & Research Outlook
 
El Inicio De La Edad Media
El Inicio De La Edad MediaEl Inicio De La Edad Media
El Inicio De La Edad Media
 
Fibromialgia y Sindrome de Fatiga Cronica
Fibromialgia y Sindrome de Fatiga CronicaFibromialgia y Sindrome de Fatiga Cronica
Fibromialgia y Sindrome de Fatiga Cronica
 
2012-10-16 - WebTechCon 2012: HTML5 & WebGL
2012-10-16 - WebTechCon 2012: HTML5 & WebGL2012-10-16 - WebTechCon 2012: HTML5 & WebGL
2012-10-16 - WebTechCon 2012: HTML5 & WebGL
 
2012-09-18 - HTML5 & WebGL
2012-09-18 - HTML5 & WebGL2012-09-18 - HTML5 & WebGL
2012-09-18 - HTML5 & WebGL
 

Mehr von Johannes Hoppe

2012-05-10 - UG Karlsruhe: NoSQL in .NET - mit Redis und MongoDB
2012-05-10 - UG Karlsruhe: NoSQL in .NET - mit Redis und MongoDB2012-05-10 - UG Karlsruhe: NoSQL in .NET - mit Redis und MongoDB
2012-05-10 - UG Karlsruhe: NoSQL in .NET - mit Redis und MongoDB
Johannes Hoppe
 
DMDW 5. Student Presentation - Pentaho Data Integration (Kettle)
DMDW 5. Student Presentation - Pentaho Data Integration (Kettle)DMDW 5. Student Presentation - Pentaho Data Integration (Kettle)
DMDW 5. Student Presentation - Pentaho Data Integration (Kettle)
Johannes Hoppe
 

Mehr von Johannes Hoppe (20)

2017 - NoSQL Vorlesung Mosbach
2017 - NoSQL Vorlesung Mosbach2017 - NoSQL Vorlesung Mosbach
2017 - NoSQL Vorlesung Mosbach
 
NoSQL - Hands on
NoSQL - Hands onNoSQL - Hands on
NoSQL - Hands on
 
Einführung in Angular 2
Einführung in Angular 2Einführung in Angular 2
Einführung in Angular 2
 
MDC kompakt 2014: Hybride Apps mit Cordova, AngularJS und Ionic
MDC kompakt 2014: Hybride Apps mit Cordova, AngularJS und IonicMDC kompakt 2014: Hybride Apps mit Cordova, AngularJS und Ionic
MDC kompakt 2014: Hybride Apps mit Cordova, AngularJS und Ionic
 
2015 02-09 - NoSQL Vorlesung Mosbach
2015 02-09 - NoSQL Vorlesung Mosbach2015 02-09 - NoSQL Vorlesung Mosbach
2015 02-09 - NoSQL Vorlesung Mosbach
 
2012-06-25 - MapReduce auf Azure
2012-06-25 - MapReduce auf Azure2012-06-25 - MapReduce auf Azure
2012-06-25 - MapReduce auf Azure
 
2013-06-25 - HTML5 & JavaScript Security
2013-06-25 - HTML5 & JavaScript Security2013-06-25 - HTML5 & JavaScript Security
2013-06-25 - HTML5 & JavaScript Security
 
2013-06-24 - Software Craftsmanship with JavaScript
2013-06-24 - Software Craftsmanship with JavaScript2013-06-24 - Software Craftsmanship with JavaScript
2013-06-24 - Software Craftsmanship with JavaScript
 
2013-06-15 - Software Craftsmanship mit JavaScript
2013-06-15 - Software Craftsmanship mit JavaScript2013-06-15 - Software Craftsmanship mit JavaScript
2013-06-15 - Software Craftsmanship mit JavaScript
 
2013 05-03 - HTML5 & JavaScript Security
2013 05-03 -  HTML5 & JavaScript Security2013 05-03 -  HTML5 & JavaScript Security
2013 05-03 - HTML5 & JavaScript Security
 
2013-03-23 - NoSQL Spartakiade
2013-03-23 - NoSQL Spartakiade2013-03-23 - NoSQL Spartakiade
2013-03-23 - NoSQL Spartakiade
 
2013-02-21 - .NET UG Rhein-Neckar: JavaScript Best Practices
2013-02-21 - .NET UG Rhein-Neckar: JavaScript Best Practices2013-02-21 - .NET UG Rhein-Neckar: JavaScript Best Practices
2013-02-21 - .NET UG Rhein-Neckar: JavaScript Best Practices
 
2012-08-29 - NoSQL Bootcamp (Redis, RavenDB & MongoDB für .NET Entwickler)
2012-08-29 - NoSQL Bootcamp (Redis, RavenDB & MongoDB für .NET Entwickler)2012-08-29 - NoSQL Bootcamp (Redis, RavenDB & MongoDB für .NET Entwickler)
2012-08-29 - NoSQL Bootcamp (Redis, RavenDB & MongoDB für .NET Entwickler)
 
2012-05-14 NoSQL in .NET - mit Redis und MongoDB
2012-05-14 NoSQL in .NET - mit Redis und MongoDB2012-05-14 NoSQL in .NET - mit Redis und MongoDB
2012-05-14 NoSQL in .NET - mit Redis und MongoDB
 
2012-05-10 - UG Karlsruhe: NoSQL in .NET - mit Redis und MongoDB
2012-05-10 - UG Karlsruhe: NoSQL in .NET - mit Redis und MongoDB2012-05-10 - UG Karlsruhe: NoSQL in .NET - mit Redis und MongoDB
2012-05-10 - UG Karlsruhe: NoSQL in .NET - mit Redis und MongoDB
 
2012-03-20 - Getting started with Node.js and MongoDB on MS Azure
2012-03-20 - Getting started with Node.js and MongoDB on MS Azure2012-03-20 - Getting started with Node.js and MongoDB on MS Azure
2012-03-20 - Getting started with Node.js and MongoDB on MS Azure
 
2012-01-31 NoSQL in .NET
2012-01-31 NoSQL in .NET2012-01-31 NoSQL in .NET
2012-01-31 NoSQL in .NET
 
2011-12-13 NoSQL aus der Praxis
2011-12-13 NoSQL aus der Praxis2011-12-13 NoSQL aus der Praxis
2011-12-13 NoSQL aus der Praxis
 
DMDW 8. Student Presentation - Groovy to MongoDB
DMDW 8. Student Presentation - Groovy to MongoDBDMDW 8. Student Presentation - Groovy to MongoDB
DMDW 8. Student Presentation - Groovy to MongoDB
 
DMDW 5. Student Presentation - Pentaho Data Integration (Kettle)
DMDW 5. Student Presentation - Pentaho Data Integration (Kettle)DMDW 5. Student Presentation - Pentaho Data Integration (Kettle)
DMDW 5. Student Presentation - Pentaho Data Integration (Kettle)
 

Kürzlich hochgeladen

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 

Kürzlich hochgeladen (20)

Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 

2012-04-12 - AOP .NET UserGroup Niederrhein

  • 2. Johannes Hoppe ASP.NET MVC Webentwickler www.johanneshoppe.de
  • 5. Business Code public class CustomerProcesses { public void RentBook( int bookId, int customerId ) { Book book = Book.GetById( bookId ); Customer customer = Customer.GetById( customerId ); book.RentedTo = customer; customer.AccountLines.Add( string.Format( "Rental of book {0}.", book ), book.RentalPrice ); customer.Balance -= book.RentalPrice; } }
  • 7.
  • 8. Business Code public class CustomerProcesses { public void RentBook( int bookId, int customerId ) { Book book = Book.GetById( bookId ); Customer customer = Customer.GetById( customerId ); book.RentedTo = customer; customer.AccountLines.Add( string.Format( "Rental of book {0}.", book ), book.RentalPrice ); customer.Balance -= book.RentalPrice; } }
  • 9. Business Code + Logging internal class CustomerProcesses { private static readonly TraceSource trace = new TraceSource( typeof (CustomerProcesses).FullName ); public void RentBook( int bookId, int customerId ) { trace.TraceInformation( "Entering CustomerProcesses.CreateCustomer( bookId = {0}, customerId = {1} )", bookId, customerId ); try { Book book = Book.GetById( bookId ); Customer customer = Customer.GetById( customerId ); book.RentedTo = customer; customer.AccountLines.Add( string.Format( "Rental of book {0}.", book ), book.RentalPrice ); customer.Balance -= book.RentalPrice; trace.TraceInformation( "Leaving CustomerProcesses.CreateCustomer( bookId = {0}, customerId = {1} )", bookId, customerId ); } catch ( Exception e ) { trace.TraceEvent( TraceEventType.Error, 0, "Exception: CustomerProcesses.CreateCustomer( bookId = {0}, customerId = {1} ) failed : {2}", bookId, customerId, e.Message ); throw; } } }
  • 10. Business Code + Logging internal class CustomerProcesses + Vorbedingungen { private static readonly TraceSource trace = new TraceSource(typeof(CustomerProcesses).FullName); public void RentBook(int bookId, int customerId) { if (bookId <= 0) throw new ArgumentOutOfRangeException("bookId"); if (customerId <= 0) throw new ArgumentOutOfRangeException("customerId"); trace.TraceInformation( "Entering CustomerProcesses.CreateCustomer( bookId = {0}, customerId = {1} )", bookId, customerId); try { Book book = Book.GetById(bookId); Customer customer = Customer.GetById(customerId); book.RentedTo = customer; customer.AccountLines.Add(string.Format("Rental of book {0}.", book), book.RentalPrice); customer.Balance -= book.RentalPrice; trace.TraceInformation( "Leaving CustomerProcesses.CreateCustomer( bookId = {0}, customerId = {1} )“, bookId, customerId); } catch (Exception e) { trace.TraceEvent(TraceEventType.Error, 0, "Exception: CustomerProcesses.CreateCustomer( bookId = {0}, customerId = {1} ) failed : {2}", bookId, customerId, e.Message); throw; } } }
  • 11. Business Code + Logging + Transaktionen + Vorbedingungen internal class CustomerProcesses ts.Complete(); { } private static readonly TraceSource trace = new TraceSource(typeof(CustomerProcesses).FullName); break; } public void RentBook(int bookId, int customerId) catch (TransactionConflictException) { { if (bookId <= 0) if (i < 3) throw new ArgumentOutOfRangeException("bookId"); continue; if (customerId <= 0) else throw new ArgumentOutOfRangeException("customerId"); throw; } trace.TraceInformation( } "Entering CustomerProcesses.CreateCustomer( bookId = {0}, customerId = {1} )“, bookId, customerId); trace.TraceInformation( "Leaving CustomerProcesses.CreateCustomer( try bookId = {0}, customerId = {1} )", { bookId, customerId); for (int i = 0; ; i++) } { catch (Exception e) try { { trace.TraceEvent(TraceEventType.Error, 0, using (var ts = new TransactionScope()) "Exception: CustomerProcesses.CreateCustomer( bookId = {0}, { customerId = {1} ) failed : {2}", Book book = Book.GetById(bookId); bookId, customerId, e.Message); Customer customer = throw; Customer.GetById(customerId); } } book.RentedTo = customer; customer.AccountLines.Add( } string.Format("Rental of book {0}.", book), book.RentalPrice); customer.Balance -= book.RentalPrice;
  • 12. Business Code + Logging + Transaktionen + Vorbedingungen + Exception Handling internal class CustomerProcesses { ts.Complete(); private static readonly TraceSource trace = } new TraceSource(typeof(CustomerProcesses).FullName); break; public void RentBook(int bookId, int customerId) } { catch ( TransactionConflictException ) if (bookId <= 0) throw new ArgumentOutOfRangeException("bookId"); { if (customerId <= 0) if ( i < 3 ) throw new ArgumentOutOfRangeException("customerId"); continue; else try throw; { } trace.TraceInformation( } "Entering CustomerProcesses.CreateCustomer( bookId = {0}, customerId = {1} )", trace.TraceInformation( bookId, customerId ); "Leaving CustomerProcesses.CreateCustomer( bookId = {0}, customerId = {1} )", try bookId, customerId ); { } for ( int i = 0;; i++ ) catch ( Exception e ) { { try trace.TraceEvent( TraceEventType.Error, 0, { "Exception: CustomerProcesses.CreateCustomer( using ( var ts = new TransactionScope() ) bookId = {0}, customerId = {1} ) failed : {2}", { bookId, customerId, e.Message ); Book book = Book.GetById( bookId ); throw; Customer customer = Customer.GetById( customerId ); } } book.RentedTo = customer; catch ( Exception e ) customer.AccountLines.Add( { string.Format( "Rental of book {0}.", book ), if (ExceptionManager.Handle(e)) throw; book.RentalPrice ); } customer.Balance -= book.RentalPrice; }
  • 13. Business Code + Logging + Transaktionen + Vorbedingungen + Exception Handling + Feature X + Feature Y + Feature Z +…
  • 14. Kern- Seperation funktionalitäten of Concerns (Core Concerns)
  • 15. VS
  • 16. VS Nicht- Funktionale Anforderungen (Crosscutting Concerns)
  • 17. Cross-Cutting Concerns Security Data Binding Exception Handling Thread Sync Tracing Caching Monitoring Validation Transaction …
  • 19. Spring.NET PostSharp LinFu Castle MS Unity Build-Time Hybrid Run-Time
  • 20. Build-Time: “Statisch” Run-Time: “Dynamisch” Erfolgt bei Kompilierung Erfolgt zur Laufzeit Code wird direkt verändert Code bleibt unverändert Zur Laufzeit keine Änderungen Zur Laufzeit Änderungen möglich Auch auf Properties, Felder, Aufruf wird über Proxy Events anwendbar umgeleitet Keine Interfaces erforderlich idR. Interfaces erforderlich (Proxy)
  • 22.
  • 23. Logging LogTimeAspect webnoteaop.codeplex.com
  • 24. Exceptions ConvertExceptionAspect webnoteaop.codeplex.com
  • 25. Validierung ValidationGuardAspect webnoteaop.codeplex.com
  • 26. Caching SimpleCacheAspect webnoteaop.codeplex.com
  • 27.
  • 29. AspectJ Begriffe Join Point Pointcut Advice Aspect
  • 30. AspectJ Begriffe Join Point Pointcut Advice Aspect
  • 31. IL Code Vorher [LogTimeAspect] public ActionResult Index() { IEnumerable<NoteWithCategories> notes = this.WebNoteService.ReadAll(); return View(notes); }
  • 32. IL Code Nachher public ActionResult Index() { ActionResult CS$1$2__returnValue; MethodExecutionArgs CS$0$3__aspectArgs = new MethodExecutionArgs(null, null); <>z__Aspects.a68.OnEntry(CS$0$3__aspectArgs); try { IEnumerable<NoteWithCategories> notes = this.WebNoteService.ReadAll(); ActionResult CS$1$0000 = base.View(notes); CS$1$2__returnValue = CS$1$0000; } finally { <>z__Aspects.a68.OnExit(CS$0$3__aspectArgs); } return CS$1$2__returnValue; }
  • 33. Originale Methode Aspekt Klasse OnEntry try { Method Body OnSuccess } catch (Exception e) { OnException } finally { OnExit } : OnMethodBoundaryAspect
  • 37. Spring.NET PostSharp springframework.net sharpcrafters.com Castle Demo Download castleproject.org webnoteaop.codeplex.com Unity unity.codeplex.com
  • 39. Bis bald › 10.05.2012 – .NET UG Karlsruhe: NoSQL › 14.05.2012 – .NET Developer Conference (DDC) .Nürnberg: NoSQL
  • 41. Primitive Aspekt-Typen › MethodBoundaryAspect › LocationInterceptionAspect › OnEntry › OnGetValue › OnSuccess › OnSetValue › OnException › OnExit › EventInterceptionAspect › OnAddHandler › OnExceptionAspect › OnRemoveHandler › OnException › OnInvokeHandler › MethodInterceptionAspect › MethodImplementationAspect › OnInvoke › OnInvoke › CompositionAspect › CreateImplementationObject
  • 42. Bildnachweise Ausgewählter Ordner © Spectral-Design – Fotolia.com Warnhinweis-Schild © Sascha Tiebel – Fotolia.com Liste abhaken © Dirk Schumann – Fotolia.com 3D rendering of an architecture model 2 © Franck Boston – Fotolia.com Healthcare © ArtmannWitte – Fotolia.com Stressed businessman © Selecstock – Fotolia.com Funny cartoon boss © artenot – Fotolia.com