SlideShare una empresa de Scribd logo
1 de 37
AspektOrientierteProgrammierungmit .NET Eine praktische Einführung 27.06.2011 Dipl.-Inf. (FH) Johannes Hoppe
Johannes Hoppe ASP.NET MVC Webentwickler www.johanneshoppe.de
01 Architektur und Patterns
Patterns Entwurfsmuster  == unser täglicher Job
Beispiel
Aber…
Business Code publicclassCustomerProcesses { publicvoid 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 internalclassCustomerProcesses { privatestaticreadonlyTraceSource trace = newTraceSource( typeof (CustomerProcesses).FullName );   publicvoid 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 internalclassCustomerProcesses { privatestaticreadonlyTraceSource trace = newTraceSource(typeof(CustomerProcesses).FullName);   publicvoid RentBook(int bookId, int customerId)     { if (bookId <= 0) thrownewArgumentOutOfRangeException("bookId"); if (customerId <= 0) thrownewArgumentOutOfRangeException("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;         }     } } + Logging + Vorbedingungen
Business Code + Logging+ Transaktionen + Vorbedingungen internalclassCustomerProcesses { privatestaticreadonlyTraceSource trace = newTraceSource(typeof(CustomerProcesses).FullName);   publicvoid RentBook(int bookId, int customerId)     { if (bookId <= 0) thrownewArgumentOutOfRangeException("bookId"); if (customerId <= 0) thrownewArgumentOutOfRangeException("customerId");           trace.TraceInformation( "Entering CustomerProcesses.CreateCustomer( bookId = {0},            customerId = {1} )“,  bookId, customerId);   try         { for (int i = 0; ; i++)             { try                 { using (var ts = newTransactionScope())                     { 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;                           ts.Complete();                     }   break;                 } catch (TransactionConflictException)                 { if (i < 3) continue; else throw;                 }             }               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	+ Exception Handling internalclassCustomerProcesses { privatestaticreadonlyTraceSource trace = newTraceSource(typeof(CustomerProcesses).FullName);   publicvoid RentBook(int bookId, int customerId)     { if (bookId <= 0) thrownewArgumentOutOfRangeException("bookId"); if (customerId <= 0) thrownewArgumentOutOfRangeException("customerId");   try         {             trace.TraceInformation( "Entering CustomerProcesses.CreateCustomer(                  bookId = {0}, customerId = {1} )",                 bookId, customerId );   try             { for ( int i = 0;; i++ )                 { try                     { using ( var ts = newTransactionScope() )                         { 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;                               ts.Complete();                         }   break;                     } catch ( TransactionConflictException )                     { if ( i < 3 ) continue; else throw;                     }                 }                   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;             }         } catch ( Exception e )         { if (ExceptionManager.Handle(e)) throw;         }     } }
Business Code + Logging+ Transaktionen + Vorbedingungen	+ Exception Handling + Feature X + Feature Y + Feature Z + …
Kern-funktionalitäten (Core Concerns) SeperationofConcerns
VS
VS Nicht-Funktionale Anforderungen(CrosscuttingConcerns)
Cross-CuttingConcerns Data Binding Thread Sync Caching Validation … Security Exception Handling Tracing Monitoring Transaction
OOP OOP+ AOP
Spring.NET Castle MS Unity PostSharp LinFu Build-Time Run-Time Hybrid
Erfolgt zur Laufzeit Code bleibt unverändert Aufruf wird über Proxy umgeleitet Zur Laufzeit keine Änderungen Aufruf wird über Proxyumgeleitet Aspekte zur Laufzeitkonfigurierbar Erfolgt bei Kompilierung Code wird direkt verändert Keine Interfaces erforderlich Zur Laufzeit keine Änderungen Auch auf Properties, Felder,Events anwendbar Kann Member und Interfaces hinzufügen Build-Time:  “Statisch” Run-Time:  “Dynamisch”
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] publicActionResult Index() { IEnumerable<NoteWithCategories> notes =  this.WebNoteService.ReadAll(); return View(notes); }
IL Code Nachher publicActionResult 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; }
OriginaleMethode Aspect Klasse OnEntry try{} catch (Exception e){}finally{} Method Body OnSuccess OnException OnExit : OnMethodBoundaryAspect
Links Spring.NET springframework.net Castle castleproject.org Unity unity.codeplex.com PostSharp sharpcrafters.com Demo Download webnoteaop.codeplex.com
FRAGEN?
Vielen Dank! Johannes Hoppe
Aspect- Typen MethodBoundaryAspect OnEntry OnSuccess OnException OnExit OnExceptionAspect OnException MethodInterceptionAspect OnInvoke LocationInterceptionAspect OnGetValue OnSetValue EventInterceptionAspect OnAddHandler OnRemoveHandler OnInvokeHandler MethodImplementationAspect 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

Más contenido relacionado

Similar a 2011-06-27 - AOP - .NET User Group Rhein Neckar

Lo Mejor Del Pdc2008 El Futrode C#
Lo Mejor Del Pdc2008 El Futrode C#Lo Mejor Del Pdc2008 El Futrode C#
Lo Mejor Del Pdc2008 El Futrode C#Juan Pablo
 
Project: Call Center Management
Project: Call Center ManagementProject: Call Center Management
Project: Call Center Managementpritamkumar
 
GraphQL - when REST API is not enough - lessons learned
GraphQL - when REST API is not enough - lessons learnedGraphQL - when REST API is not enough - lessons learned
GraphQL - when REST API is not enough - lessons learnedMarcinStachniuk
 
June2013 Meetup : In-App Billing by Soham & Senthil
June2013 Meetup : In-App Billing by Soham & SenthilJune2013 Meetup : In-App Billing by Soham & Senthil
June2013 Meetup : In-App Billing by Soham & SenthilBlrDroid
 
C#을 이용한 task 병렬화와 비동기 패턴
C#을 이용한 task 병렬화와 비동기 패턴C#을 이용한 task 병렬화와 비동기 패턴
C#을 이용한 task 병렬화와 비동기 패턴명신 김
 
4Developers: Mateusz Stasch- Domain Events - czyli jak radzić sobie z rzeczyw...
4Developers: Mateusz Stasch- Domain Events - czyli jak radzić sobie z rzeczyw...4Developers: Mateusz Stasch- Domain Events - czyli jak radzić sobie z rzeczyw...
4Developers: Mateusz Stasch- Domain Events - czyli jak radzić sobie z rzeczyw...PROIDEA
 
Knockoutjs UG meeting presentation
Knockoutjs UG meeting presentationKnockoutjs UG meeting presentation
Knockoutjs UG meeting presentationValdis Iljuconoks
 
Multi client
Multi clientMulti client
Multi clientAisy Cuyy
 
AuthN deep.dive—ASP.NET Authentication Internals.pdf
AuthN deep.dive—ASP.NET Authentication Internals.pdfAuthN deep.dive—ASP.NET Authentication Internals.pdf
AuthN deep.dive—ASP.NET Authentication Internals.pdfondrejl1
 
MultiClient chatting berbasis gambar
MultiClient chatting berbasis gambarMultiClient chatting berbasis gambar
MultiClient chatting berbasis gambaryoyomay93
 
HashiCorp Vault Plugin Infrastructure
HashiCorp Vault Plugin InfrastructureHashiCorp Vault Plugin Infrastructure
HashiCorp Vault Plugin InfrastructureNicolas Corrarello
 
Simple design/programming nuggets
Simple design/programming nuggetsSimple design/programming nuggets
Simple design/programming nuggetsVivek Singh
 
Mythbusting: Understanding How We Measure the Performance of MongoDB
Mythbusting: Understanding How We Measure the Performance of MongoDBMythbusting: Understanding How We Measure the Performance of MongoDB
Mythbusting: Understanding How We Measure the Performance of MongoDBMongoDB
 
Dependency injection - the right way
Dependency injection - the right wayDependency injection - the right way
Dependency injection - the right wayThibaud Desodt
 

Similar a 2011-06-27 - AOP - .NET User Group Rhein Neckar (20)

Apex Design Patterns
Apex Design PatternsApex Design Patterns
Apex Design Patterns
 
Lo Mejor Del Pdc2008 El Futrode C#
Lo Mejor Del Pdc2008 El Futrode C#Lo Mejor Del Pdc2008 El Futrode C#
Lo Mejor Del Pdc2008 El Futrode C#
 
Project: Call Center Management
Project: Call Center ManagementProject: Call Center Management
Project: Call Center Management
 
Functional DDD
Functional DDDFunctional DDD
Functional DDD
 
GraphQL - when REST API is not enough - lessons learned
GraphQL - when REST API is not enough - lessons learnedGraphQL - when REST API is not enough - lessons learned
GraphQL - when REST API is not enough - lessons learned
 
June2013 Meetup : In-App Billing by Soham & Senthil
June2013 Meetup : In-App Billing by Soham & SenthilJune2013 Meetup : In-App Billing by Soham & Senthil
June2013 Meetup : In-App Billing by Soham & Senthil
 
Domain Driven Design 101
Domain Driven Design 101Domain Driven Design 101
Domain Driven Design 101
 
C#을 이용한 task 병렬화와 비동기 패턴
C#을 이용한 task 병렬화와 비동기 패턴C#을 이용한 task 병렬화와 비동기 패턴
C#을 이용한 task 병렬화와 비동기 패턴
 
Muster in Webcontrollern
Muster in WebcontrollernMuster in Webcontrollern
Muster in Webcontrollern
 
4Developers: Mateusz Stasch- Domain Events - czyli jak radzić sobie z rzeczyw...
4Developers: Mateusz Stasch- Domain Events - czyli jak radzić sobie z rzeczyw...4Developers: Mateusz Stasch- Domain Events - czyli jak radzić sobie z rzeczyw...
4Developers: Mateusz Stasch- Domain Events - czyli jak radzić sobie z rzeczyw...
 
Knockoutjs UG meeting presentation
Knockoutjs UG meeting presentationKnockoutjs UG meeting presentation
Knockoutjs UG meeting presentation
 
Service Workers
Service WorkersService Workers
Service Workers
 
Multi client
Multi clientMulti client
Multi client
 
Quick Fix Sample
Quick Fix SampleQuick Fix Sample
Quick Fix Sample
 
AuthN deep.dive—ASP.NET Authentication Internals.pdf
AuthN deep.dive—ASP.NET Authentication Internals.pdfAuthN deep.dive—ASP.NET Authentication Internals.pdf
AuthN deep.dive—ASP.NET Authentication Internals.pdf
 
MultiClient chatting berbasis gambar
MultiClient chatting berbasis gambarMultiClient chatting berbasis gambar
MultiClient chatting berbasis gambar
 
HashiCorp Vault Plugin Infrastructure
HashiCorp Vault Plugin InfrastructureHashiCorp Vault Plugin Infrastructure
HashiCorp Vault Plugin Infrastructure
 
Simple design/programming nuggets
Simple design/programming nuggetsSimple design/programming nuggets
Simple design/programming nuggets
 
Mythbusting: Understanding How We Measure the Performance of MongoDB
Mythbusting: Understanding How We Measure the Performance of MongoDBMythbusting: Understanding How We Measure the Performance of MongoDB
Mythbusting: Understanding How We Measure the Performance of MongoDB
 
Dependency injection - the right way
Dependency injection - the right wayDependency injection - the right way
Dependency injection - the right way
 

Más de Johannes Hoppe

2017 - NoSQL Vorlesung Mosbach
2017 - NoSQL Vorlesung Mosbach2017 - NoSQL Vorlesung Mosbach
2017 - NoSQL Vorlesung MosbachJohannes Hoppe
 
Einführung in Angular 2
Einführung in Angular 2Einführung in Angular 2
Einführung in Angular 2Johannes Hoppe
 
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 IonicJohannes Hoppe
 
2015 02-09 - NoSQL Vorlesung Mosbach
2015 02-09 - NoSQL Vorlesung Mosbach2015 02-09 - NoSQL Vorlesung Mosbach
2015 02-09 - NoSQL Vorlesung MosbachJohannes Hoppe
 
2012-06-25 - MapReduce auf Azure
2012-06-25 - MapReduce auf Azure2012-06-25 - MapReduce auf Azure
2012-06-25 - MapReduce auf AzureJohannes Hoppe
 
2013-06-25 - HTML5 & JavaScript Security
2013-06-25 - HTML5 & JavaScript Security2013-06-25 - HTML5 & JavaScript Security
2013-06-25 - HTML5 & JavaScript SecurityJohannes Hoppe
 
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 JavaScriptJohannes Hoppe
 
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 JavaScriptJohannes Hoppe
 
2013 05-03 - HTML5 & JavaScript Security
2013 05-03 -  HTML5 & JavaScript Security2013 05-03 -  HTML5 & JavaScript Security
2013 05-03 - HTML5 & JavaScript SecurityJohannes Hoppe
 
2013-03-23 - NoSQL Spartakiade
2013-03-23 - NoSQL Spartakiade2013-03-23 - NoSQL Spartakiade
2013-03-23 - NoSQL SpartakiadeJohannes Hoppe
 
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 dbJohannes Hoppe
 
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 PracticesJohannes Hoppe
 
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 & WebGLJohannes Hoppe
 
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 MongodbJohannes Hoppe
 
2012-09-18 - HTML5 & WebGL
2012-09-18 - HTML5 & WebGL2012-09-18 - HTML5 & WebGL
2012-09-18 - HTML5 & WebGLJohannes Hoppe
 
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 & MongoDBJohannes Hoppe
 
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)Johannes Hoppe
 
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 MongoDBJohannes 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 MongoDBJohannes Hoppe
 

Más de 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-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
 
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-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-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
 
2012-09-18 - HTML5 & WebGL
2012-09-18 - HTML5 & WebGL2012-09-18 - HTML5 & WebGL
2012-09-18 - HTML5 & WebGL
 
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
 
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
 

Último

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, ...apidays
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
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 FMESafe Software
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Bhuvaneswari Subramani
 
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 Takeoffsammart93
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityWSO2
 
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...apidays
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistandanishmna97
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 

Último (20)

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, ...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
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
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
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
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
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...
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 

2011-06-27 - AOP - .NET User Group Rhein Neckar

  • 1. AspektOrientierteProgrammierungmit .NET Eine praktische Einführung 27.06.2011 Dipl.-Inf. (FH) Johannes Hoppe
  • 2. Johannes Hoppe ASP.NET MVC Webentwickler www.johanneshoppe.de
  • 4. Patterns Entwurfsmuster == unser täglicher Job
  • 7. Business Code publicclassCustomerProcesses { publicvoid 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; } }
  • 8. Business Code + Logging internalclassCustomerProcesses { privatestaticreadonlyTraceSource trace = newTraceSource( typeof (CustomerProcesses).FullName );   publicvoid 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; }   } }
  • 9. Business Code internalclassCustomerProcesses { privatestaticreadonlyTraceSource trace = newTraceSource(typeof(CustomerProcesses).FullName);   publicvoid RentBook(int bookId, int customerId) { if (bookId <= 0) thrownewArgumentOutOfRangeException("bookId"); if (customerId <= 0) thrownewArgumentOutOfRangeException("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; } } } + Logging + Vorbedingungen
  • 10. Business Code + Logging+ Transaktionen + Vorbedingungen internalclassCustomerProcesses { privatestaticreadonlyTraceSource trace = newTraceSource(typeof(CustomerProcesses).FullName);   publicvoid RentBook(int bookId, int customerId) { if (bookId <= 0) thrownewArgumentOutOfRangeException("bookId"); if (customerId <= 0) thrownewArgumentOutOfRangeException("customerId");   trace.TraceInformation( "Entering CustomerProcesses.CreateCustomer( bookId = {0}, customerId = {1} )“, bookId, customerId);   try { for (int i = 0; ; i++) { try { using (var ts = newTransactionScope()) { 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;   ts.Complete(); }   break; } catch (TransactionConflictException) { if (i < 3) continue; else throw; } }   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 + Exception Handling internalclassCustomerProcesses { privatestaticreadonlyTraceSource trace = newTraceSource(typeof(CustomerProcesses).FullName);   publicvoid RentBook(int bookId, int customerId) { if (bookId <= 0) thrownewArgumentOutOfRangeException("bookId"); if (customerId <= 0) thrownewArgumentOutOfRangeException("customerId");   try { trace.TraceInformation( "Entering CustomerProcesses.CreateCustomer( bookId = {0}, customerId = {1} )", bookId, customerId );   try { for ( int i = 0;; i++ ) { try { using ( var ts = newTransactionScope() ) { 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;   ts.Complete(); }   break; } catch ( TransactionConflictException ) { if ( i < 3 ) continue; else throw; } }   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; } } catch ( Exception e ) { if (ExceptionManager.Handle(e)) throw; } } }
  • 12. Business Code + Logging+ Transaktionen + Vorbedingungen + Exception Handling + Feature X + Feature Y + Feature Z + …
  • 14. VS
  • 16. Cross-CuttingConcerns Data Binding Thread Sync Caching Validation … Security Exception Handling Tracing Monitoring Transaction
  • 18. Spring.NET Castle MS Unity PostSharp LinFu Build-Time Run-Time Hybrid
  • 19. Erfolgt zur Laufzeit Code bleibt unverändert Aufruf wird über Proxy umgeleitet Zur Laufzeit keine Änderungen Aufruf wird über Proxyumgeleitet Aspekte zur Laufzeitkonfigurierbar Erfolgt bei Kompilierung Code wird direkt verändert Keine Interfaces erforderlich Zur Laufzeit keine Änderungen Auch auf Properties, Felder,Events anwendbar Kann Member und Interfaces hinzufügen Build-Time: “Statisch” Run-Time: “Dynamisch”
  • 21.
  • 26.
  • 27. 03 AOP 1 x 1
  • 28. AspectJ Begriffe Join Point Pointcut Advice Aspect
  • 29. AspectJ Begriffe Join Point Pointcut Advice Aspect
  • 30. IL Code Vorher [LogTimeAspect] publicActionResult Index() { IEnumerable<NoteWithCategories> notes = this.WebNoteService.ReadAll(); return View(notes); }
  • 31. IL Code Nachher publicActionResult 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; }
  • 32. OriginaleMethode Aspect Klasse OnEntry try{} catch (Exception e){}finally{} Method Body OnSuccess OnException OnExit : OnMethodBoundaryAspect
  • 33. Links Spring.NET springframework.net Castle castleproject.org Unity unity.codeplex.com PostSharp sharpcrafters.com Demo Download webnoteaop.codeplex.com
  • 36. Aspect- Typen MethodBoundaryAspect OnEntry OnSuccess OnException OnExit OnExceptionAspect OnException MethodInterceptionAspect OnInvoke LocationInterceptionAspect OnGetValue OnSetValue EventInterceptionAspect OnAddHandler OnRemoveHandler OnInvokeHandler MethodImplementationAspect OnInvoke CompositionAspect CreateImplementationObject
  • 37. 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