Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
AspektOrientierteProgrammierungmit .NET<br />Eine praktische Einführung<br />27.06.2011<br />Dipl.-Inf. (FH) Johannes Hopp...
Johannes Hoppe<br />ASP.NET MVC Webentwickler<br />www.johanneshoppe.de<br />
01<br />Architektur und Patterns<br />
Patterns<br />Entwurfsmuster <br />==<br />unser täglicher Job<br />
Beispiel<br />
Aber…<br />
Business Code<br />publicclassCustomerProcesses<br />{<br />publicvoid RentBook( int bookId, int customerId )<br />    {<b...
Business Code<br />+ Logging<br />internalclassCustomerProcesses<br />{<br />privatestaticreadonlyTraceSource trace =<br /...
Business Code<br />internalclassCustomerProcesses<br />{<br />privatestaticreadonlyTraceSource trace =<br />newTraceSource...
Business Code<br />+ Logging+ Transaktionen<br />+ Vorbedingungen<br />internalclassCustomerProcesses<br />{<br />privates...
Business Code<br />+ Logging+ Transaktionen<br />+ Vorbedingungen	+ Exception Handling<br />internalclassCustomerProcesses...
Business Code<br />+ Logging+ Transaktionen<br />+ Vorbedingungen	+ Exception Handling<br />+ Feature X<br />+ Feature Y<b...
Kern-funktionalitäten<br />(Core Concerns)<br />SeperationofConcerns<br />
VS<br />
VS<br />Nicht-Funktionale Anforderungen(CrosscuttingConcerns)<br />
Cross-CuttingConcerns<br />Data Binding<br />Thread Sync<br />Caching<br />Validation<br />…<br />Security<br />Exception ...
OOP<br />OOP+ AOP<br />
Spring.NET<br />Castle<br />MS Unity<br />PostSharp<br />LinFu<br />Build-Time<br />Run-Time<br />Hybrid<br />
Erfolgt zur Laufzeit<br />Code bleibt unverändert<br />Aufruf wird über Proxy umgeleitet<br />Zur Laufzeit keine Änderunge...
02<br />Live Coding<br />
Logging<br />LogTimeAspect<br />webnoteaop.codeplex.com<br />
Exceptions<br />ConvertExceptionAspect<br />webnoteaop.codeplex.com<br />
Validierung<br />ValidationGuardAspect<br />webnoteaop.codeplex.com<br />
Caching<br />SimpleCacheAspect<br />webnoteaop.codeplex.com<br />
03<br />AOP 1 x 1<br />
AspectJ Begriffe<br />Join Point<br />Pointcut<br />Advice<br />Aspect<br />
AspectJ Begriffe<br />Join Point<br />Pointcut<br />Advice<br />Aspect<br />
IL Code Vorher<br />[LogTimeAspect]<br />publicActionResult Index()<br />{<br />IEnumerable<NoteWithCategories> notes = <b...
IL Code Nachher<br />publicActionResult Index()<br />{<br />ActionResult CS$1$2__returnValue;<br />MethodExecutionArgs CS$...
OriginaleMethode<br />Aspect Klasse<br />OnEntry<br />try{}<br />catch (Exception e){}finally{}<br />Method Body<br />OnSu...
Links<br />Spring.NET<br />springframework.net<br />Castle<br />castleproject.org<br />Unity<br />unity.codeplex.com<br />...
FRAGEN?<br />
Vielen Dank!<br />Johannes Hoppe<br />
Aspect- Typen<br />MethodBoundaryAspect<br />OnEntry<br />OnSuccess<br />OnException<br />OnExit<br />OnExceptionAspect<br...
Bildnachweise<br />Ausgewählter Ordner © Spectral-Design – Fotolia.com<br />Warnhinweis-Schild © Sascha Tiebel – Fotolia.c...
Upcoming SlideShare
Loading in …5
×

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

3,026 views

Published on

Published in: Technology, Business
  • DOWNLOAD FULL eBOOK INTO AVAILABLE FORMAT ......................................................................................................................... ......................................................................................................................... 1.DOWNLOAD FULL. PDF eBook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB eBook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... 1.DOWNLOAD FULL. doc eBook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... 1.DOWNLOAD FULL. PDF eBook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB eBook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... 1.DOWNLOAD FULL. doc eBook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, CookeBOOK Crime, eeBOOK Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD FULL eBOOK INTO AVAILABLE FORMAT ......................................................................................................................... ......................................................................................................................... 1.DOWNLOAD FULL. PDF eBook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB eBook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... 1.DOWNLOAD FULL. doc eBook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... 1.DOWNLOAD FULL. PDF eBook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... 1.DOWNLOAD FULL. EPUB eBook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... 1.DOWNLOAD FULL. doc eBook here { https://tinyurl.com/y3nhqquc } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, CookeBOOK Crime, eeBOOK Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Be the first to like this

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

  1. 1. AspektOrientierteProgrammierungmit .NET<br />Eine praktische Einführung<br />27.06.2011<br />Dipl.-Inf. (FH) Johannes Hoppe<br />
  2. 2. Johannes Hoppe<br />ASP.NET MVC Webentwickler<br />www.johanneshoppe.de<br />
  3. 3. 01<br />Architektur und Patterns<br />
  4. 4. Patterns<br />Entwurfsmuster <br />==<br />unser täglicher Job<br />
  5. 5. Beispiel<br />
  6. 6. Aber…<br />
  7. 7. Business Code<br />publicclassCustomerProcesses<br />{<br />publicvoid RentBook( int bookId, int customerId )<br /> {<br />Book book = Book.GetById( bookId );<br />Customer customer = Customer.GetById( customerId );<br /> <br /> book.RentedTo = customer;<br /> customer.AccountLines.Add(string.Format( "Rental of book {0}.", book ), book.RentalPrice );<br /> customer.Balance -= book.RentalPrice;<br /> }<br />}<br />
  8. 8. Business Code<br />+ Logging<br />internalclassCustomerProcesses<br />{<br />privatestaticreadonlyTraceSource trace =<br />newTraceSource( typeof (CustomerProcesses).FullName );<br /> <br />publicvoid RentBook( int bookId, int customerId )<br /> {<br /> trace.TraceInformation(<br />"Entering CustomerProcesses.CreateCustomer( bookId = {0}, customerId = {1} )",<br /> bookId, customerId ); try{ <br /> Book book = Book.GetById( bookId );<br />Customer customer = Customer.GetById( customerId );<br /> <br /> book.RentedTo = customer;<br /> customer.AccountLines.Add( string.Format( "Rental of book {0}.", book ), book.RentalPrice );<br /> customer.Balance -= book.RentalPrice;<br /> trace.TraceInformation(<br /> "Leaving CustomerProcesses.CreateCustomer( bookId = {0}, customerId = {1} )",<br /> bookId, customerId );<br /> }<br /> catch ( Exception e )<br /> {<br /> trace.TraceEvent( TraceEventType.Error, 0,<br /> "Exception: CustomerProcesses.CreateCustomer( bookId = {0}, customerId = {1} ) failed : {2}",<br /> bookId, customerId, e.Message );<br /> throw;<br /> }  <br /> }<br />}<br />
  9. 9. Business Code<br />internalclassCustomerProcesses<br />{<br />privatestaticreadonlyTraceSource trace =<br />newTraceSource(typeof(CustomerProcesses).FullName);<br /> <br />publicvoid RentBook(int bookId, int customerId)<br /> {<br />if (bookId <= 0) thrownewArgumentOutOfRangeException("bookId");<br />if (customerId <= 0) thrownewArgumentOutOfRangeException("customerId");<br /> <br /> trace.TraceInformation(<br />"Entering CustomerProcesses.CreateCustomer( bookId = {0}, customerId = {1} )",<br /> bookId, customerId);<br /> <br />try<br /> {<br />Book book = Book.GetById(bookId);<br />Customer customer = Customer.GetById(customerId);<br /> <br /> book.RentedTo = customer;<br /> customer.AccountLines.Add(string.Format("Rental of book {0}.", book), book.RentalPrice);<br /> customer.Balance -= book.RentalPrice;<br /> <br /> trace.TraceInformation(<br />"Leaving CustomerProcesses.CreateCustomer( bookId = {0}, customerId = {1} )“, bookId, customerId);<br /> }<br />catch (Exception e)<br /> {<br /> trace.TraceEvent(TraceEventType.Error, 0,<br /> "Exception: CustomerProcesses.CreateCustomer( bookId = {0}, customerId = {1} ) failed : {2}",<br /> bookId, customerId, e.Message);<br />throw;<br /> }<br /> }<br />}<br />+ Logging<br />+ Vorbedingungen<br />
  10. 10. Business Code<br />+ Logging+ Transaktionen<br />+ Vorbedingungen<br />internalclassCustomerProcesses<br />{<br />privatestaticreadonlyTraceSource trace =<br />newTraceSource(typeof(CustomerProcesses).FullName);<br /> <br />publicvoid RentBook(int bookId, int customerId)<br /> {<br />if (bookId <= 0) thrownewArgumentOutOfRangeException("bookId");<br />if (customerId <= 0) thrownewArgumentOutOfRangeException("customerId");<br /> <br /> trace.TraceInformation(<br />"Entering CustomerProcesses.CreateCustomer( bookId = {0}, customerId = {1} )“, bookId, customerId);<br /> <br />try<br /> {<br />for (int i = 0; ; i++)<br /> {<br />try<br /> {<br />using (var ts = newTransactionScope())<br /> {<br />Book book = Book.GetById(bookId);<br />Customer customer = Customer.GetById(customerId);<br /> <br /> book.RentedTo = customer;<br /> customer.AccountLines.Add(string.Format("Rental of book {0}.", book), book.RentalPrice);<br /> customer.Balance -= book.RentalPrice;<br /> <br /> ts.Complete();<br /> }<br /> <br />break;<br /> }<br />catch (TransactionConflictException)<br /> {<br />if (i < 3)<br />continue;<br />else<br />throw;<br /> }<br /> }<br /> <br /> trace.TraceInformation(<br />"Leaving CustomerProcesses.CreateCustomer( bookId = {0}, customerId = {1} )",<br /> bookId, customerId);<br /> }<br />catch (Exception e)<br /> {<br /> trace.TraceEvent(TraceEventType.Error, 0,<br />"Exception: CustomerProcesses.CreateCustomer( bookId = {0}, customerId = {1} ) failed : {2}",<br /> bookId, customerId, e.Message);<br />throw;<br /> }<br /> }<br />}<br />
  11. 11. Business Code<br />+ Logging+ Transaktionen<br />+ Vorbedingungen + Exception Handling<br />internalclassCustomerProcesses<br />{<br />privatestaticreadonlyTraceSource trace =<br />newTraceSource(typeof(CustomerProcesses).FullName);<br /> <br />publicvoid RentBook(int bookId, int customerId)<br /> {<br />if (bookId <= 0) thrownewArgumentOutOfRangeException("bookId");<br />if (customerId <= 0) thrownewArgumentOutOfRangeException("customerId");<br /> <br />try<br /> {<br /> trace.TraceInformation(<br />"Entering CustomerProcesses.CreateCustomer( bookId = {0}, customerId = {1} )",<br /> bookId, customerId );<br /> <br />try<br /> {<br />for ( int i = 0;; i++ )<br /> {<br />try<br /> {<br />using ( var ts = newTransactionScope() )<br /> {<br />Book book = Book.GetById( bookId );<br />Customer customer = Customer.GetById( customerId );<br /> <br /> book.RentedTo = customer;<br /> customer.AccountLines.Add( string.Format( "Rental of book {0}.", book ), book.RentalPrice );<br /> customer.Balance -= book.RentalPrice;<br /> <br /> ts.Complete();<br /> }<br /> <br />break;<br /> }<br />catch ( TransactionConflictException )<br /> {<br />if ( i < 3 )<br />continue;<br />else<br />throw;<br /> }<br /> }<br /> <br /> trace.TraceInformation(<br />"Leaving CustomerProcesses.CreateCustomer( bookId = {0}, customerId = {1} )",<br /> bookId, customerId );<br /> }<br />catch ( Exception e )<br /> {<br /> trace.TraceEvent( TraceEventType.Error, 0,<br />"Exception: CustomerProcesses.CreateCustomer( bookId = {0}, customerId = {1} ) failed : {2}",<br /> bookId, customerId, e.Message );<br />throw;<br /> }<br /> }<br />catch ( Exception e )<br /> {<br />if (ExceptionManager.Handle(e)) throw;<br /> }<br /> }<br />}<br />
  12. 12. Business Code<br />+ Logging+ Transaktionen<br />+ Vorbedingungen + Exception Handling<br />+ Feature X<br />+ Feature Y<br />+ Feature Z<br />+ …<br />
  13. 13. Kern-funktionalitäten<br />(Core Concerns)<br />SeperationofConcerns<br />
  14. 14. VS<br />
  15. 15. VS<br />Nicht-Funktionale Anforderungen(CrosscuttingConcerns)<br />
  16. 16. Cross-CuttingConcerns<br />Data Binding<br />Thread Sync<br />Caching<br />Validation<br />…<br />Security<br />Exception Handling<br />Tracing<br />Monitoring<br />Transaction<br />
  17. 17. OOP<br />OOP+ AOP<br />
  18. 18. Spring.NET<br />Castle<br />MS Unity<br />PostSharp<br />LinFu<br />Build-Time<br />Run-Time<br />Hybrid<br />
  19. 19. Erfolgt zur Laufzeit<br />Code bleibt unverändert<br />Aufruf wird über Proxy umgeleitet<br />Zur Laufzeit keine Änderungen<br />Aufruf wird über Proxyumgeleitet<br />Aspekte zur Laufzeitkonfigurierbar<br />Erfolgt bei Kompilierung<br />Code wird direkt verändert<br />Keine Interfaces erforderlich<br />Zur Laufzeit keine Änderungen<br />Auch auf Properties, Felder,Events anwendbar<br />Kann Member und Interfaces hinzufügen<br />Build-Time: “Statisch”<br />Run-Time: “Dynamisch”<br />
  20. 20. 02<br />Live Coding<br />
  21. 21.
  22. 22. Logging<br />LogTimeAspect<br />webnoteaop.codeplex.com<br />
  23. 23. Exceptions<br />ConvertExceptionAspect<br />webnoteaop.codeplex.com<br />
  24. 24. Validierung<br />ValidationGuardAspect<br />webnoteaop.codeplex.com<br />
  25. 25. Caching<br />SimpleCacheAspect<br />webnoteaop.codeplex.com<br />
  26. 26.
  27. 27. 03<br />AOP 1 x 1<br />
  28. 28. AspectJ Begriffe<br />Join Point<br />Pointcut<br />Advice<br />Aspect<br />
  29. 29. AspectJ Begriffe<br />Join Point<br />Pointcut<br />Advice<br />Aspect<br />
  30. 30. IL Code Vorher<br />[LogTimeAspect]<br />publicActionResult Index()<br />{<br />IEnumerable<NoteWithCategories> notes = <br />this.WebNoteService.ReadAll();<br />return View(notes);<br />}<br />
  31. 31. IL Code Nachher<br />publicActionResult Index()<br />{<br />ActionResult CS$1$2__returnValue;<br />MethodExecutionArgs CS$0$3__aspectArgs =<br />new MethodExecutionArgs(null, null);<br /> <>z__Aspects.a68.OnEntry(CS$0$3__aspectArgs);<br />try<br /> {<br />IEnumerable<NoteWithCategories> notes =<br /> this.WebNoteService.ReadAll();<br />ActionResult CS$1$0000 = base.View(notes);<br /> CS$1$2__returnValue = CS$1$0000;<br /> }<br />finally<br /> {<br /> <>z__Aspects.a68.OnExit(CS$0$3__aspectArgs);<br /> }<br />return CS$1$2__returnValue;<br />}<br />
  32. 32. OriginaleMethode<br />Aspect Klasse<br />OnEntry<br />try{}<br />catch (Exception e){}finally{}<br />Method Body<br />OnSuccess<br />OnException<br />OnExit<br />: OnMethodBoundaryAspect<br />
  33. 33. Links<br />Spring.NET<br />springframework.net<br />Castle<br />castleproject.org<br />Unity<br />unity.codeplex.com<br />PostSharp<br />sharpcrafters.com<br />Demo Download<br />webnoteaop.codeplex.com<br />
  34. 34. FRAGEN?<br />
  35. 35. Vielen Dank!<br />Johannes Hoppe<br />
  36. 36. Aspect- Typen<br />MethodBoundaryAspect<br />OnEntry<br />OnSuccess<br />OnException<br />OnExit<br />OnExceptionAspect<br />OnException<br />MethodInterceptionAspect<br />OnInvoke<br />LocationInterceptionAspect<br />OnGetValue<br />OnSetValue<br />EventInterceptionAspect<br />OnAddHandler<br />OnRemoveHandler<br />OnInvokeHandler<br />MethodImplementationAspect<br />OnInvoke<br />CompositionAspect<br />CreateImplementationObject<br />
  37. 37. Bildnachweise<br />Ausgewählter Ordner © Spectral-Design – Fotolia.com<br />Warnhinweis-Schild © Sascha Tiebel – Fotolia.com<br />Liste abhaken © Dirk Schumann – Fotolia.com<br />3D rendering of an architecture model 2 © Franck Boston – Fotolia.com<br />Healthcare © ArtmannWitte – Fotolia.com<br />Stressed businessman © Selecstock – Fotolia.com<br />
  38. 38. Farben Primär<br />
  39. 39. Farben Code<br />

×