2
votes

I have a WCF service that uses Castle Windsor and Nhibernate, currently I am using LifestylePerWebRequest and everythig works fine. I want to add to the service so that it also listens to messages from a queue and essentially call the same methods that the webservice, however I realize this might not work as my Nhibernate repositories are using the LifestylePerWebRequest scope.

Can I set dynamically change the lifestyle depending on the situation?

Thanks

1
Your real problem here is not understandable, please explain the scenario in detail. Will your WCF service listen a queue? What is the relation between your Repository and the listening logic? If you need a component for two different concern, you can register it twice with different lifestyles.mehmet mecek
Why your Repositories are per web request, you can register them as singleton if they are stateless (they should be stateless), however you must register the nhibernate Session perwebrequest or per thread because Session can not be used more than one threads.mehmet mecek
I have the same issue. For me everything works in the context of a WCF call but when I try to access my repos from within the (Windows) service it complains. Did you find a solution?Quinn Wilson
@QuinnWilson unfortunately I cannot remember what the solution was for this. The service could take WCF requests but was also connected to a pub/sub broker via rabbitmq. Its from an old job and I dont have access to the code.pogorman

1 Answers

0
votes

Have you checked 'WCF Integration Facility' for Castle Windsor?

I think you should have a look on it.

There are several specific lifestyles that can help you (e.g. PerWcfSession or PerWcfOperation)

If you need different lifestyles for different applications you can use custom installers for every application.