Created
July 7, 2010 14:49
-
-
Save kkozmic/466792 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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