SlideShare a Scribd company logo
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

More Related Content

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

Apex Design Patterns
Apex Design PatternsApex Design Patterns
Apex Design Patterns
Salesforce Developers
 
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 Management
pritamkumar
 
Functional DDD
Functional DDDFunctional DDD
Functional DDD
Alessandro Melchiori
 
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
MarcinStachniuk
 
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
BlrDroid
 
Domain Driven Design 101
Domain Driven Design 101Domain Driven Design 101
Domain Driven Design 101
Richard Dingwall
 
C#을 이용한 task 병렬화와 비동기 패턴
C#을 이용한 task 병렬화와 비동기 패턴C#을 이용한 task 병렬화와 비동기 패턴
C#을 이용한 task 병렬화와 비동기 패턴
명신 김
 
Muster in Webcontrollern
Muster in WebcontrollernMuster in Webcontrollern
Muster in Webcontrollern
Jens Himmelreich
 
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 presentation
Valdis Iljuconoks
 
Service Workers
Service WorkersService Workers
Service Workers
Artur Felipe Sousa
 
Multi client
Multi clientMulti client
Multi client
Aisy Cuyy
 
Quick Fix Sample
Quick Fix SampleQuick Fix Sample
Quick Fix Sample
Neeraj Kaushik
 
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
ondrejl1
 
MultiClient chatting berbasis gambar
MultiClient chatting berbasis gambarMultiClient chatting berbasis gambar
MultiClient chatting berbasis gambar
yoyomay93
 
HashiCorp Vault Plugin Infrastructure
HashiCorp Vault Plugin InfrastructureHashiCorp Vault Plugin Infrastructure
HashiCorp Vault Plugin Infrastructure
Nicolas Corrarello
 
Simple design/programming nuggets
Simple design/programming nuggetsSimple design/programming nuggets
Simple design/programming nuggets
Vivek 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 MongoDB
MongoDB
 
Dependency injection - the right way
Dependency injection - the right wayDependency injection - the right way
Dependency injection - the right way
Thibaud Desodt
 

Similar to 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
 

More from Johannes Hoppe

2017 - NoSQL Vorlesung Mosbach
2017 - NoSQL Vorlesung Mosbach2017 - NoSQL Vorlesung Mosbach
2017 - NoSQL Vorlesung Mosbach
Johannes Hoppe
 
NoSQL - Hands on
NoSQL - Hands onNoSQL - Hands on
NoSQL - Hands on
Johannes Hoppe
 
Einführung in Angular 2
Einführung in Angular 2Einführung in Angular 2
Einführung in Angular 2
Johannes 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 Ionic
Johannes Hoppe
 
2015 02-09 - NoSQL Vorlesung Mosbach
2015 02-09 - NoSQL Vorlesung Mosbach2015 02-09 - NoSQL Vorlesung Mosbach
2015 02-09 - NoSQL Vorlesung Mosbach
Johannes Hoppe
 
2012-06-25 - MapReduce auf Azure
2012-06-25 - MapReduce auf Azure2012-06-25 - MapReduce auf Azure
2012-06-25 - MapReduce auf Azure
Johannes Hoppe
 
2013-06-25 - HTML5 & JavaScript Security
2013-06-25 - HTML5 & JavaScript Security2013-06-25 - HTML5 & JavaScript Security
2013-06-25 - HTML5 & JavaScript Security
Johannes 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 JavaScript
Johannes 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 JavaScript
Johannes Hoppe
 
2013 05-03 - HTML5 & JavaScript Security
2013 05-03 -  HTML5 & JavaScript Security2013 05-03 -  HTML5 & JavaScript Security
2013 05-03 - HTML5 & JavaScript Security
Johannes Hoppe
 
2013-03-23 - NoSQL Spartakiade
2013-03-23 - NoSQL Spartakiade2013-03-23 - NoSQL Spartakiade
2013-03-23 - NoSQL Spartakiade
Johannes 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 db
Johannes 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 Practices
Johannes 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 & WebGL
Johannes 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 & MongoDB
Johannes 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 MongoDB
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 MongoDBJohannes Hoppe
 

More from 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
 

Recently uploaded

The Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptxThe Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptx
operationspcvita
 
AppSec PNW: Android and iOS Application Security with MobSF
AppSec PNW: Android and iOS Application Security with MobSFAppSec PNW: Android and iOS Application Security with MobSF
AppSec PNW: Android and iOS Application Security with MobSF
Ajin Abraham
 
Digital Banking in the Cloud: How Citizens Bank Unlocked Their Mainframe
Digital Banking in the Cloud: How Citizens Bank Unlocked Their MainframeDigital Banking in the Cloud: How Citizens Bank Unlocked Their Mainframe
Digital Banking in the Cloud: How Citizens Bank Unlocked Their Mainframe
Precisely
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
panagenda
 
Mutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented ChatbotsMutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented Chatbots
Pablo Gómez Abajo
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
Chart Kalyan
 
Leveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and StandardsLeveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and Standards
Neo4j
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
akankshawande
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Alpen-Adria-Universität
 
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
Edge AI and Vision Alliance
 
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and BioinformaticiansBiomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Neo4j
 
What is an RPA CoE? Session 1 – CoE Vision
What is an RPA CoE?  Session 1 – CoE VisionWhat is an RPA CoE?  Session 1 – CoE Vision
What is an RPA CoE? Session 1 – CoE Vision
DianaGray10
 
Dandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity serverDandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity server
Antonios Katsarakis
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
Zilliz
 
"Frontline Battles with DDoS: Best practices and Lessons Learned", Igor Ivaniuk
"Frontline Battles with DDoS: Best practices and Lessons Learned",  Igor Ivaniuk"Frontline Battles with DDoS: Best practices and Lessons Learned",  Igor Ivaniuk
"Frontline Battles with DDoS: Best practices and Lessons Learned", Igor Ivaniuk
Fwdays
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
DanBrown980551
 
Principle of conventional tomography-Bibash Shahi ppt..pptx
Principle of conventional tomography-Bibash Shahi ppt..pptxPrinciple of conventional tomography-Bibash Shahi ppt..pptx
Principle of conventional tomography-Bibash Shahi ppt..pptx
BibashShahi
 
Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |
AstuteBusiness
 

Recently uploaded (20)

The Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptxThe Microsoft 365 Migration Tutorial For Beginner.pptx
The Microsoft 365 Migration Tutorial For Beginner.pptx
 
AppSec PNW: Android and iOS Application Security with MobSF
AppSec PNW: Android and iOS Application Security with MobSFAppSec PNW: Android and iOS Application Security with MobSF
AppSec PNW: Android and iOS Application Security with MobSF
 
Digital Banking in the Cloud: How Citizens Bank Unlocked Their Mainframe
Digital Banking in the Cloud: How Citizens Bank Unlocked Their MainframeDigital Banking in the Cloud: How Citizens Bank Unlocked Their Mainframe
Digital Banking in the Cloud: How Citizens Bank Unlocked Their Mainframe
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
 
Mutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented ChatbotsMutation Testing for Task-Oriented Chatbots
Mutation Testing for Task-Oriented Chatbots
 
Artificial Intelligence and Electronic Warfare
Artificial Intelligence and Electronic WarfareArtificial Intelligence and Electronic Warfare
Artificial Intelligence and Electronic Warfare
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdfHow to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
How to Interpret Trends in the Kalyan Rajdhani Mix Chart.pdf
 
Leveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and StandardsLeveraging the Graph for Clinical Trials and Standards
Leveraging the Graph for Clinical Trials and Standards
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
 
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
“How Axelera AI Uses Digital Compute-in-memory to Deliver Fast and Energy-eff...
 
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and BioinformaticiansBiomedical Knowledge Graphs for Data Scientists and Bioinformaticians
Biomedical Knowledge Graphs for Data Scientists and Bioinformaticians
 
What is an RPA CoE? Session 1 – CoE Vision
What is an RPA CoE?  Session 1 – CoE VisionWhat is an RPA CoE?  Session 1 – CoE Vision
What is an RPA CoE? Session 1 – CoE Vision
 
Dandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity serverDandelion Hashtable: beyond billion requests per second on a commodity server
Dandelion Hashtable: beyond billion requests per second on a commodity server
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
 
"Frontline Battles with DDoS: Best practices and Lessons Learned", Igor Ivaniuk
"Frontline Battles with DDoS: Best practices and Lessons Learned",  Igor Ivaniuk"Frontline Battles with DDoS: Best practices and Lessons Learned",  Igor Ivaniuk
"Frontline Battles with DDoS: Best practices and Lessons Learned", Igor Ivaniuk
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
 
Principle of conventional tomography-Bibash Shahi ppt..pptx
Principle of conventional tomography-Bibash Shahi ppt..pptxPrinciple of conventional tomography-Bibash Shahi ppt..pptx
Principle of conventional tomography-Bibash Shahi ppt..pptx
 
Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |Astute Business Solutions | Oracle Cloud Partner |
Astute Business Solutions | Oracle Cloud Partner |
 

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