DomainService for each connected user

Jun 17, 2010 at 5:26 PM
In this sample, a DomainService is created for each connected user of the application. If there were a thousand people connected, it seems that there would be a thousand DomainServices created instead of just one that services all connections. While I like how it stores the current state of the user, it seems to be that the number of DomainService objects might become a problem. In an app that I am working on, I just get the current user each time that I need it on the server. This seems to me to be less stateful, something that seems to be of benefit on the server. The other issue I ran into when trying to implement this is that I have quite a few different domain service types, and I found I needed to remember to extend the CreateDomainService Method each time. Not a big issue really. Any suggestions on the above? Thanks, Greg
Coordinator
Jun 19, 2010 at 11:00 AM

A DomainService instance is not created per user. An instance is created per request. Each service instance is also stateless - the state from one request isn't held around for use in a subsequent request.

CreateDomainService is an example implementation - a larger app might use an IoC container of sorts rather than hand roll a specific implementation. On the other hand, some real apps are small, and a manual implementation suffices.