SlideShare una empresa de Scribd logo
1 de 42
Descargar para leer sin conexión
AOP mit .NET



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



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

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



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

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

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

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

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

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

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

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

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

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

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

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


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



 OOP
+ AOP
Spring.NET
PostSharp    LinFu    Castle
                      MS Unity




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

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




          webnoteaop.codeplex.com
Exceptions
ConvertExceptionAspect




                         webnoteaop.codeplex.com
Validierung
ValidationGuardAspect




                        webnoteaop.codeplex.com
Caching
SimpleCacheAspect




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




                   Join Point
                   Pointcut
                   Advice
                   Aspect
AspectJ Begriffe




                   Join Point
                   Pointcut
                   Advice
                   Aspect
IL Code Vorher




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

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

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

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


Castle                Demo Download
castleproject.org     webnoteaop.codeplex.com


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


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

›   MethodInterceptionAspect   ›   MethodImplementationAspect
    › OnInvoke                     › OnInvoke

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

Más contenido relacionado

Destacado

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
 
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
 
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
 
Tema 4 conocimiento reproducción humana
Tema 4 conocimiento reproducción humanaTema 4 conocimiento reproducción humana
Tema 4 conocimiento reproducción humanaAna María Rodriguez
 
Modelling Natural Ventilation in IES-VE: Case studies & Research Outlook
Modelling Natural Ventilation in IES-VE: Case studies & Research OutlookModelling Natural Ventilation in IES-VE: Case studies & Research Outlook
Modelling Natural Ventilation in IES-VE: Case studies & Research OutlookIES VE
 
El Inicio De La Edad Media
El Inicio De La Edad MediaEl Inicio De La Edad Media
El Inicio De La Edad Mediazhuyibamu
 
Fibromialgia y Sindrome de Fatiga Cronica
Fibromialgia y Sindrome de Fatiga CronicaFibromialgia y Sindrome de Fatiga Cronica
Fibromialgia y Sindrome de Fatiga CronicaConsultoris Vitae
 
2012-10-16 - WebTechCon 2012: HTML5 & WebGL
2012-10-16 - WebTechCon 2012: HTML5 & WebGL2012-10-16 - WebTechCon 2012: HTML5 & WebGL
2012-10-16 - WebTechCon 2012: HTML5 & WebGLJohannes Hoppe
 
2012-09-18 - HTML5 & WebGL
2012-09-18 - HTML5 & WebGL2012-09-18 - HTML5 & WebGL
2012-09-18 - HTML5 & WebGLJohannes Hoppe
 

Destacado (9)

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

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-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-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
 
2012-03-20 - Getting started with Node.js and MongoDB on MS Azure
2012-03-20 - Getting started with Node.js and MongoDB on MS Azure2012-03-20 - Getting started with Node.js and MongoDB on MS Azure
2012-03-20 - Getting started with Node.js and MongoDB on MS AzureJohannes Hoppe
 
2012-01-31 NoSQL in .NET
2012-01-31 NoSQL in .NET2012-01-31 NoSQL in .NET
2012-01-31 NoSQL in .NETJohannes Hoppe
 
2011-12-13 NoSQL aus der Praxis
2011-12-13 NoSQL aus der Praxis2011-12-13 NoSQL aus der Praxis
2011-12-13 NoSQL aus der PraxisJohannes Hoppe
 
DMDW 8. Student Presentation - Groovy to MongoDB
DMDW 8. Student Presentation - Groovy to MongoDBDMDW 8. Student Presentation - Groovy to MongoDB
DMDW 8. Student Presentation - Groovy to MongoDBJohannes Hoppe
 
DMDW 5. Student Presentation - Pentaho Data Integration (Kettle)
DMDW 5. Student Presentation - Pentaho Data Integration (Kettle)DMDW 5. Student Presentation - Pentaho Data Integration (Kettle)
DMDW 5. Student Presentation - Pentaho Data Integration (Kettle)Johannes Hoppe
 

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-21 - .NET UG Rhein-Neckar: JavaScript Best Practices
2013-02-21 - .NET UG Rhein-Neckar: JavaScript Best Practices2013-02-21 - .NET UG Rhein-Neckar: JavaScript Best Practices
2013-02-21 - .NET UG Rhein-Neckar: JavaScript Best Practices
 
2012-08-29 - NoSQL Bootcamp (Redis, RavenDB & MongoDB für .NET Entwickler)
2012-08-29 - NoSQL Bootcamp (Redis, RavenDB & MongoDB für .NET Entwickler)2012-08-29 - NoSQL Bootcamp (Redis, RavenDB & MongoDB für .NET Entwickler)
2012-08-29 - NoSQL Bootcamp (Redis, RavenDB & MongoDB für .NET Entwickler)
 
2012-05-14 NoSQL in .NET - mit Redis und MongoDB
2012-05-14 NoSQL in .NET - mit Redis und MongoDB2012-05-14 NoSQL in .NET - mit Redis und MongoDB
2012-05-14 NoSQL in .NET - mit Redis und MongoDB
 
2012-05-10 - UG Karlsruhe: NoSQL in .NET - mit Redis und MongoDB
2012-05-10 - UG Karlsruhe: NoSQL in .NET - mit Redis und MongoDB2012-05-10 - UG Karlsruhe: NoSQL in .NET - mit Redis und MongoDB
2012-05-10 - UG Karlsruhe: NoSQL in .NET - mit Redis und MongoDB
 
2012-03-20 - Getting started with Node.js and MongoDB on MS Azure
2012-03-20 - Getting started with Node.js and MongoDB on MS Azure2012-03-20 - Getting started with Node.js and MongoDB on MS Azure
2012-03-20 - Getting started with Node.js and MongoDB on MS Azure
 
2012-01-31 NoSQL in .NET
2012-01-31 NoSQL in .NET2012-01-31 NoSQL in .NET
2012-01-31 NoSQL in .NET
 
2011-12-13 NoSQL aus der Praxis
2011-12-13 NoSQL aus der Praxis2011-12-13 NoSQL aus der Praxis
2011-12-13 NoSQL aus der Praxis
 
DMDW 8. Student Presentation - Groovy to MongoDB
DMDW 8. Student Presentation - Groovy to MongoDBDMDW 8. Student Presentation - Groovy to MongoDB
DMDW 8. Student Presentation - Groovy to MongoDB
 
DMDW 5. Student Presentation - Pentaho Data Integration (Kettle)
DMDW 5. Student Presentation - Pentaho Data Integration (Kettle)DMDW 5. Student Presentation - Pentaho Data Integration (Kettle)
DMDW 5. Student Presentation - Pentaho Data Integration (Kettle)
 

Último

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
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
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 

Último (20)

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
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
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 

2012-04-12 - AOP .NET UserGroup Niederrhein

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