Skip to content

Instantly share code, notes, and snippets.

@kkozmic
Created July 7, 2010 14:49
Show Gist options
  • Save kkozmic/466792 to your computer and use it in GitHub Desktop.
Save kkozmic/466792 to your computer and use it in GitHub Desktop.
public class DataAccessInstaller:IWindsorInstaller
{
public void Install(IWindsorContainer container, IConfigurationStore store)
{
container.Kernel.ComponentModelBuilder.AddContributor(new SubmitChangesDataContextContributor());
container.Register(Component.For<DataDataContext>()
.LifeStyle.PerWebRequest
// some other components
);
}
}
public class SubmitChangesDataContextContributor : IContributeComponentModelConstruction
{
public void ProcessModel(IKernel kernel, ComponentModel model)
{
if (typeof (DataContext).IsAssignableFrom(model.Implementation))
{
// first so that it runs before DisposalConcern
model.LifecycleSteps.AddFirst(LifecycleStepType.Commission, new SubmitChangesConcern());
}
}
}
public class SubmitChangesConcern : ILifecycleConcern
{
public void Apply(ComponentModel model, object component)
{
using (var scope = new TransactionScope())
{
var dataContext = (DataContext) component;
dataContext.SubmitChanges();
scope.Complete();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment