protected override void Init() { ILogger _Logger = NullLogger.Instance; // check we have a logger factory if (Kernel.HasComponent(typeof(ILoggerFactory))) { // get logger factory var loggerFactory = Kernel.Resolve <ILoggerFactory>(); // get logger _Logger = loggerFactory.Create(typeof(AutoTxFacility)); } if (_Logger.IsDebugEnabled) { _Logger.Debug("initializing AutoTxFacility"); } if (!Kernel.HasComponent(typeof(ILogger))) { Trace.TraceWarning("Missing ILogger in Kernel; add it or you'll have no logging of errors!"); Kernel.Register(Component.For <ILogger>().Instance(NullLogger.Instance)); } Kernel.Register( // the interceptor needs to be created for every method call Component.For <TransactionInterceptor>() .LifeStyle.Transient, Component.For <ITransactionMetaInfoStore>() .ImplementedBy <TransactionClassMetaInfoStore>() .LifeStyle.Singleton, Component.For <ITransactionManager>() .ImplementedBy <TransactionManager>() .LifeStyle.Singleton .Forward(typeof(TransactionManager)), // the activity manager shouldn't have the same lifestyle as TransactionInterceptor, as it // calls a static .Net/Mono framework method, and it's the responsibility of // that framework method to keep track of the call context. Component.For <IActivityManager>() .ImplementedBy <CallContextActivityManager>() .LifeStyle.Singleton //Component.For<IDirectoryAdapter>() // .ImplementedBy<DirectoryAdapter>() // .LifeStyle.PerTransaction(), //Component.For<IFileAdapter>() // .ImplementedBy<FileAdapter>() // .LifeStyle.PerTransaction(), //Component.For<IMapPath>() // .ImplementedBy<MapPathImpl>() // .LifeStyle.Transient ); var componentInspector = new TransactionalComponentInspector(); Kernel.ComponentModelBuilder.AddContributor(componentInspector); _Logger.Debug( "inspecting previously registered components; this might throw if you have configured your components in the wrong way"); ((INamingSubSystem)Kernel.GetSubSystem(SubSystemConstants.NamingKey)) .GetAllHandlers() .Do(x => componentInspector.ProcessModel(Kernel, x.ComponentModel)) .Run(); _Logger.Debug( @"Initialized AutoTxFacility: If you are experiencing problems, go to https://github.com/castleproject/Castle.Transactions and file a ticket for the Transactions project. You can enable verbose logging for .Net by adding this to you .config file: <system.diagnostics> <sources> <source name=""System.Transactions"" switchValue=""Information""> <listeners> <add name=""tx"" type=""Castle.Transactions.Logging.TraceListener, Castle.Transactions""/> </listeners> </source> </sources> </system.diagnostics> If you wish to e.g. roll back a transaction from within a transactional method you can resolve/use the ITransactionManager's CurrentTransaction property and invoke Rollback on it. Be ready to catch TransactionAbortedException from the caller. You can enable debugging through log4net. "); }
protected override void Init() { _Logger.Debug("initializing AutoTxFacility"); Kernel.Register( // the interceptor needs to be created for every method call Component.For<TransactionInterceptor>() .Named("transaction.interceptor") .LifeStyle.Transient, Component.For<ITransactionMetaInfoStore>() .ImplementedBy<TransactionClassMetaInfoStore>() .Named("transaction.metaInfoStore") .LifeStyle.Singleton, Component.For<ITransactionManager>() .ImplementedBy<TransactionManager>() .Named("transaction.manager") .LifeStyle.Singleton .Forward(typeof (TransactionManager)), // the activity manager shouldn't have the same lifestyle as TransactionInterceptor, as it // calls a static .Net/Mono framework method, and it's the responsibility of // that framework method to keep track of the call context. Component.For<IActivityManager>() .ImplementedBy<CallContextActivityManager>() .LifeStyle.Singleton, Component.For<IDirectoryAdapter>() .ImplementedBy<DirectoryAdapter>() .LifeStyle.PerTransaction(), Component.For<IFileAdapter>() .ImplementedBy<FileAdapter>() .LifeStyle.PerTransaction(), Component.For<IMapPath>() .ImplementedBy<MapPathImpl>() .LifeStyle.Transient ); var componentInspector = new TransactionalComponentInspector(); Kernel.ComponentModelBuilder.AddContributor(componentInspector); _Logger.Debug("inspecting previously registered components; this might throw if you have configured your components in the wrong way"); ((INamingSubSystem) Kernel.GetSubSystem(SubSystemConstants.NamingKey)) .GetHandlers() .Do(x => componentInspector.ProcessModel(Kernel, x.ComponentModel)) .Run(); _Logger.Debug( @"Initialized AutoTxFacility: If you are experiencing problems, go to https://github.com/castleproject/Castle.Transactions and file a ticket for the Transactions project. You can enable verbose logging for .Net by adding this to you .config file: <system.diagnostics> <sources> <source name=""System.Transactions"" switchValue=""Information""> <listeners> <add name=""tx"" type=""Castle.Services.Transaction.Internal.TxTraceListener, Castle.Services.Transaction""/> </listeners> </source> </sources> </system.diagnostics> If you wish to e.g. roll back a transaction from within a transactional method you can resolve/use the ITransactionManager's CurrentTransaction property and invoke Rollback on it. Be ready to catch TransactionAbortedException from the caller. You can enable debugging through log4net. "); }