I'm trying to implement a UoW like shown here: https://blog.iannelson.uk/wcf-global-exception-handling/
But I can't for the life of me figure out how to wire it up with Autofac. I have absolutely no idea where to start.
I've got WCF working fine with Autofac from using http://autofac.readthedocs.org/en/latest/integration/wcf.html
But to inject or add the IEndpointBehavior? No idea...
If there's a better way to implement a UoW I would like to hear.
Edit:
For now I've just done:
builder.RegisterType(typeof (UnitOfWork))
.As(typeof (IUnitOfWork))
.InstancePerLifetimeScope()
.OnRelease(x =>
{
Trace.WriteLine("Comitted of UoW");
((IUnitOfWork) x).Commit();
// OnRelease inhibits the default Autofac Auto-Dispose behavior so explicitly chain to it
x.Dispose();
});
Though I don't know if this is an acceptable way of doing it, seems like a hack :(
Edit2:
Doesn't seem like it's possible to run a UoW in WCF :/
Edit 3:
I've posted my solution here: http://www.philliphaydon.com/2011/11/06/unit-of-work-with-wcf-and-autofac/
I have found a solution to this problem, where the unit of work only will be committed if no errors is thrown.
Register the unit of work as InstancePerLifetimeScope in Autofac
Then i have created a combined EndpointBehavior and a ErrorHandler.
The registration of the Endpoint Behavior in web.config