preparing your application to use attributes with Castle facilities - sharparchitecture/Sharp-Architecture-Contrib GitHub Wiki

You can use attributes from SharpArchContrib.CastleWindsor assembly to add Transaction managment, Logging and Exception handling. These attributes use Castle DynamicProxy to intercept and add functionality before/after method calls.

##Preparing your project##

  1. Download the verion of Contrib compatible with the verion of S#arp Architecture you are using from here.

  2. Add a reference to the following assemblies in your top level project (the project where you are initializing your container):

     SharpArchContrib.Core.dll
     SharpArchContrib.Data.dll
     SharpArchContrib.Castle.dll
     log4net.dll
    
  3. Initialize Contrib components with the container. In order for the Interceptor to be registered correctly you need to modify the method initializing the container and a call to initialize the contrib components immediatley after your container is instantiated, this needs to be done so that whenever a component is registered in the container, the Contrib facilities will check if that component has any of the attributes applied and register appropriate interceptores.

    If you register any components before calling the Contrib component registrar then the calls to methods in that compoenent will not be intercepted.

    Your container initialisation code should now look like:

     IWindsorContainer container = new WindsorContainer();
     SharpArchContrib.Castle.CastleWindsor.ComponentRegistrar.AddComponentsTo(container);  
    

    Alternatively, you can specify an implementation of ITransactionManager to use for managing transactions:

     SharpArchContrib.Castle.CastleWindsor.AddComponentsTo(container, typeof(SystemTransactionManager));
    

    to use System.Transaction.TransactionScope, or:

     SharpArchContrib.Castle.CastleWindsor.AddComponentsTo(container, typeof(NHibernateTransactionManager));
    

    to use standard NHibernate transactions (This is the default).

##Next steps##

⚠️ **GitHub.com Fallback** ⚠️