Rewriting COM+ in 10 lines of code

time to read 8 min | 1525 words

Okay, this is a lie, but it is nearly true. Take a look at this Binsor script:

def OnNewTransaction(transaction as ITransaction,  transactionMode as TransactionMode,  isolationMode as IsolationMode):

    transaction.Enlist( TransactionScopeResourceAdapter(transactionMode) )


Component(transaction_manager, ITransactionManager, DefaultTransactionManager)

IoC.Container.AddFacility("automatic_transaction_management_facility", TransactionFacility())


IoC.Container.Kernel.ComponentCreated += do(model as ComponentModel, instance as object):

    cast(ITransactionManager, instance).TransactionCreated += OnNewTransaction if instance isa ITransactionManager


activeRecordAssemblies = ( Assembly.Load("Exesto.Model"), )


Component(active_record_repository, IRepository, ARRepository)

Component(active_record_unit_of_work, IUnitOfWorkFactory, ActiveRecordUnitOfWorkFactory, assemblies: activeRecordAssemblies )


Component(just_service, JustService)

In 10 lines of code, it setup a Active Record, setup unit of work, setup automatic transaction support, bind it to my Active Record Unit Of Work Adapter (note the OnNewTransaction and registerring to the ComponentCreated event) and setup a service that uses declarative transactions.

It also slice, dice and debug ;-)

On the one hand, it opens up a whole new world of options in the configuration. On the other hand, should this stuff be in the configuration in the first place? The ability to do things on ComponentCreated, for instnace, or to register to a specific event from a service and do stuff from the configuration is very powerful. The problem is that I am very afraid of trying to maintain anything but the simplest stuff there, since it is probably the most volatile part of the application.