Hello Henrik,

Thanks for the answer.

I was just inspecting your codebase and noticed "SessionPerTransaction" and
"SessionPerWebRequest", and I would ask a "session for per wcf operation" as
I am hosting my app in a windows service with tcpNetBindings :). No need for
that now.

But looking at your wiki quick start example, I saw that we have some
different approaches to achive auto tx management. I strive to maintain my
service classes infrastructure agnostic. But your examples injects
Func<ISession> to service ctor (which can be pulled to a repository in
another example, so that's not the problem, but also uses Transaction
attribute, which cannot be pulled to another layer.

I would appreciate if you'd help me achive my "clean" approach as I am not
quite knowledgeable in WCF lifecycle.*

1.* At the orginial post by Dusty Candland (
http://candland.net/blog/2009/10/27/nhibernate-session-per-request-using-castles-wcffacility/),
he creates *WcfSessionPerRequestCallContex *with the *new *keyword (as
highligted below) :

public class WcfSessionPerRequestBehavior : IServiceBehavior
    {
        private readonly ISessionManager sessionManager;

        private string[] dbAliases = { "nh.facility.default" };

        public string[] DbAliases
        {
            get { return dbAliases; }
            set { dbAliases = value; }
        }

        public WcfSessionPerRequestBehavior(ISessionManager sessionManager)
        {
            this.sessionManager = sessionManager;
        }

        public void Validate(ServiceDescription serviceDescription,
ServiceHostBase serviceHostBase)
        {

        }

        public void AddBindingParameters(ServiceDescription
serviceDescription, ServiceHostBase serviceHostBase,
Collection<ServiceEndpoint> endpoints, BindingParameterCollection
bindingParameters)
        {

        }

        public void ApplyDispatchBehavior(ServiceDescription
serviceDescription, ServiceHostBase serviceHostBase)
        {
            foreach (var cdb in serviceHostBase.ChannelDispatchers)
            {
                var channelDispatcher = cdb as ChannelDispatcher;

                if (null != channelDispatcher)
                {
                    foreach (var endpointDispatcher in
channelDispatcher.Endpoints)
                    {
                        foreach (var dispatchOperation in
endpointDispatcher.DispatchRuntime.Operations)
                        {

dispatchOperation.CallContextInitializers.Add(new
WcfSessionPerRequestCallContextInitializer(sessionManager,
dbAliases));
                        }
                    }
                }
            }
        }
    }


Do you suggest that I should have resolve it from the container but register
as follows

.Register(Component.For<ICallContextInitializer>().ImplementedBy<WcfSessionPerRequestCallContextInitializer>().LifeStyle.PerWcfOperation())

?


*2.* With the first item implemented then, at the following class, if I
remove "string [] dbAliases" injection (because injected sessionManager
would be the right one provided by your NH facilities selector) and also
remove the foreach to traverse the string array, then can I be able use your
NH facility. In short, red highlighted must be removed, right?

public class WcfSessionPerRequestCallContextInitializer :
ICallContextInitializer
    {
        private readonly ISessionManager sessionManager;

        private readonly string[] dbAliases;

        public WcfSessionPerRequestCallContextInitializer(ISessionManager
sessionManager, string[] dbAliases)
        {
            this.sessionManager = sessionManager;
            this.dbAliases = dbAliases;
        }

        public object BeforeInvoke(InstanceContext instanceContext,
IClientChannel channel, Message message)
        {
            var extension = new NHibernateContextExtension();
            foreach (var dbAlias in dbAliases)
            {
                extension.Sessions.Add(sessionManager.OpenSession(dbAlias));
            }
            instanceContext.Extensions.Add(extension);
            return extension;
        }

        public void AfterInvoke(object correlationState)
        {
            if (correlationState != null)
            {
                ((IDisposable)correlationState).Dispose();
            }
        }
    }

Thanks again for your interest.


2011/5/23 Henrik Feldt <[email protected]>

> PS;
>
>
>
> It’s actually version 0.2 of NHFac, 3.0.0.2007 of tx.
>
>
>
> …and there’s a new concept which is default; session per transaction, which
> is what you are looking for (per operation as you say yourself)!
>
>
>
> *From:* [email protected] [mailto:
> [email protected]] *On Behalf Of *Berke Sokhan
> *Sent:* den 23 maj 2011 15:30
> *To:* [email protected]
> *Cc:* [email protected]
> *Subject:* Re: NHibernateFacility and session-per-WCF-operation
>
>
>
> Hello,
>
>
> I am trying to achive the same thing with new Castle.Facilites.NHibernate
> using one of the Richard's sources at his blog post article:
> http://candland.net/blog/2009/10/27/nhibernate-session-per-request-using-castles-wcffacility/
>
> (I didnt choose to use Richard's method because it needs to decorate
> service classes with [Transaction] attribute, which I would not prefer.)
>
> The problem is new ISessionManager.Open doesnt take a string but instead
> SessionManager's ctor takes a Func<ISession>, so the highlighted section in
> the following does not work:
>
> public class WcfSessionPerRequestCallContextInitializer : 
> ICallContextInitializer
>
>     {
>
>         private readonly ISessionManager sessionManager;
>
>          private readonly string[] dbAliases;
>
>          public WcfSessionPerRequestCallContextInitializer(ISessionManager 
> sessionManager, string[] dbAliases)
>
>         {
>
>             this.sessionManager = sessionManager;
>
>             this.dbAliases = dbAliases;
>
>         }
>
>          public object BeforeInvoke(InstanceContext instanceContext, 
> IClientChannel channel, Message message)
>
>         {
>
>             var extension = new NHibernateContextExtension();
>
>             foreach (var dbAlias in dbAliases)
>
>             {
>
>                 extension.Sessions.Add(*sessionManager.OpenSession(dbAlias)*);
>
>             }
>
>             instanceContext.Extensions.Add(extension);
>
>             return extension;
>
>         }
>
>          public void AfterInvoke(object correlationState)
>
>         {
>
>             if (correlationState != null)
>
>             {
>
>                 ((IDisposable)correlationState).Dispose();
>
>             }
>
>         }
>
>     }
>
>
> - Can you give some pointers on how to enable per WCF operation session
> with new Castle.Facilities.NHibernate?
>
> - And also I use WcfIntegration to host services, do I have an option to
> use WcfIntegration to solve this issue with a different implementation?
>
>
> Thanks,
> Berke Sökhan.
>
> 2010/8/17 Richard Dingwall <[email protected]>
>
> On Aug 12, 9:17 pm, Adam Toseland <[email protected]> wrote:
> > Hi Rich,
> >
> > I ended up implementing a solution for this based on this post.
> >
> > http://realfiction.net/go/133
> > Cheers
> > Adam,
>
> Thanks, I started with your implementation but found a way that didn't
> require any extra code:
>
>
> http://richarddingwall.name/2010/08/17/one-nhibernate-session-per-wcf-operation-the-easy-way/
>
>
> Rich
>
> --
> You received this message because you are subscribed to the Google Groups
> "Castle Project Users" group.
> To post to this group, send email to [email protected]
> .
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/castle-project-users?hl=en.
>
>
>
>
> --
> Berke SOKHAN.
>
> http://twitter.com/berkesokhan
> http://blog.berkesokhan.com
> http://www.birliktegelistir.com/editors.aspx
>
> --
> You received this message because you are subscribed to the Google Groups
> "Castle Project Users" group.
> To post to this group, send email to [email protected]
> .
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/castle-project-users?hl=en.
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Castle Project Users" group.
> To post to this group, send email to [email protected]
> .
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/castle-project-users?hl=en.
>



-- 
Berke SOKHAN.

http://twitter.com/berkesokhan
http://blog.berkesokhan.com
http://www.birliktegelistir.com/editors.aspx

-- 
You received this message because you are subscribed to the Google Groups 
"Castle Project Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/castle-project-users?hl=en.

Reply via email to