public ISession Wrap(ISession realSession, SessionCloseDelegate closeDelegate, SessionDisposeDelegate disposeDelegate)
        {
            if (IsWrapped(realSession))
            {
                return(realSession);
            }
            var wrapper = new TransactionProtectionWrapper(realSession, closeDelegate, disposeDelegate);

            return(BuildSessionWrapped(wrapper));
        }
        private static ISession BuildSessionWrapped(TransactionProtectionWrapper wrapper)
        {
            var proxyFactory = new SerializableProxyFactory
            {
                Interfaces      = Commons.SessionProxyInterfaces,
                TargetSource    = wrapper,
                ProxyTargetType = false
            };

            proxyFactory.AddAdvice(wrapper);

            return((ISession)proxyFactory.GetProxy());
        }