Hi!
How can I register the sessionfactory in IKernel?
API in the documentation is not enough for me.
I have a class as following:
______________________________
using System.Web;
using NHibernate;
using NHibernate.Cfg;
namespace WebMonitorUpdate.SQLServerServices
{
public sealed class DBConnectionService
{
static readonly DBConnectionService instance = new
DBConnectionService();
private const string CurrentSessionKey = "_session";
private static readonly ISessionFactory sessionFactory;
static DBConnectionService()
{
if(DBConnectionService.sessionFactory == null)
sessionFactory = new Configuration().Configure
().BuildSessionFactory();
}
DBConnectionService()
{
}
public static DBConnectionService Instance
{
get
{
return instance;
}
}
public ISession OpenSession()
{
HttpContext context = HttpContext.Current;
ISession currentSession = context.Items[CurrentSessionKey]
as ISession;
if (currentSession == null)
{
currentSession = sessionFactory.OpenSession();
context.Items[CurrentSessionKey] = currentSession;
}
return currentSession;
}
public void CloseSession()
{
HttpContext context = HttpContext.Current;
if (context == null) return;
ISession currentSession = context.Items[CurrentSessionKey]
as ISession;
if (currentSession == null)
{
// No current session
return;
}
currentSession.Close();
context.Items.Remove(CurrentSessionKey);
}
public void CloseSessionFactory()
{
if (sessionFactory != null)
{
sessionFactory.Close();
}
}
}
}
_________________________________
And I will register this class in the IKernel. could I do this? how?
if no, what do I missing here?!
Thanks in advance
Sheri
On 21 Jan, 19:42, Jason Meckley <[email protected]> wrote:
> there are 2 configurations in this scenario. Nhibernate andCastle.
> Nhibernate configuration is very easy to figure out using the xml
> schema docs.Castle, on the other hand is very open ended. the documentation
> (found
> herehttp://www.castleproject.org/container/documentation/v21/index.html)
> is the best place to start. because each facility/component can be
> configured uniquely there is no xml schema. however the amount ofCastlexml
> configure is greatly reduced with the fluent registration
> API.
>
> On Jan 21, 10:33 am, Sheri <[email protected]> wrote:
>
>
>
> > Thanks for your answer Jason!
>
> > I am almost newbie and I need more details. like how to configure the
> > configuration file (web.config) withcastle...
>
> > Hope somebody can help!
>
> > Regards
> > Sheri
>
> > On 21 Jan, 15:21, Jason Meckley <[email protected]> wrote:
>
> > > the 2 frameworks solve unique problems. they can be used together, but
> > > how that is done is really up to you. the common approach is to
> > > register the configuration and session factory as singletons in the
> > > container. then resolve the session from the factory by implementing
> > > ISubDependencyResolver. to resolve the same session for a given scope
> > > use the ISessionFactory.GetCurrentSession() method.
> > > defining the session and transaction boundaries is up to you. for web
> > > applications most use a Session per Request and implement a
> > > Transaction Filter.
>
> > > You can also use IoC with NH by implementing your own BytecodeProvider
> > > and ReflectionOptimizer. this isn't required, but can be helpful if
> > > dependency injection is required.
>
> > > I believe there is a Nhibernate Facility as part of theCastlesource
> > > code which handles most/all of the first paragraph above. Because I
> > > use the trunk of both NH andCastleI have found it's easier to simply
> > > roll my own facility for each project rather than manage all the
> > > project dependencies each time I build from the trunk.
>
> > > On Jan 21, 7:34 am, Sheri <[email protected]> wrote:
>
> > > > Hello!
>
> > > > Does anyone know any god link/documentation to usingCastle(Kernel/
> > > > Facilities/Windsor) in NHibernate 2.1.
>
> > > > Thanks in advance
> > > > /Sheri
--
You received this message because you are subscribed to the Google Groups
"nhusers" 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/nhusers?hl=en.