I updated the tutorial to make it more explicit what's happening.
in short:
- Init is for facility initialisation, and is called once after you
AddFacility to the container. PerWebRequest is a lifestyle of the component, and it means that at most one instance will be created for any given web request in your app.
HTH,
Krzysztof
PS
Feel free to share any other feedback, and point to places in the tutorial that you find either confusing or not explaining something well, or clearly enough so that we can improve the tutorial. If there's something that you think should be covered in the tutorial but was not, feel free to suggest topics to cover in forthcoming parts of the tutorial as well.
Hi
Thanks for the modification. However I am still unsure about the ISession creation. Does it mean that for every HTTP request an ISession is intialised? I did some SQL profiling and there only seems to be one connection. i.e. no more connections are being made no matter how many times I call an action on a controller even on multiple controllers using ISession. Could you explain whats going on and how to test it to see it in action?? Please :-)
The only other feedback I would suggest is maybe using Repositories rather than passing ISession to the Controller. I have created some repository interfaces, classes that implement the interface and in their constructors pass in a ISession and in the constructors of the controllers pass the repository interface. This seems to be a best of practice recommendation.
Something may have just clicked.
When the application starts it calls OpenSession in the PersistanceFacility.
Because this is registered as PerWebRequest does that mean for each web request this session is then shared using ISession?
Two things:
- The facility does not call
OpenSession - As Jose explained on the group, there's no 1 - 1 relation between
ISession instances and physical database connections.
In the PersistanceFacility class there is an OpenSession method call.
Anyway does my other post make sense? Once its registered the ISession is then created or passed to each web request?
there's no call to OpenSession in the facility.
There's a delegate passed as a factory method that calls it. That's a difference as this delegate is not invoked within the Init method.