views:

45

answers:

1

I'm currently setting up my session configuration via a static call such as

SessionConfiguration.GetSessionConfiguration();

The method above returns a configured ISessionFactory:

public static ISessionFactory GetSessionConfiguration()
{
    return Fluently.Configure()
        .Database(MsSqlConfiguration
            .MsSql2005
            .ConnectionString(/*...*/)
            .ShowSql()
            .CurrentSessionContext<WebSessionContext>())
        .Mappings(/*etc*/)
        .BuildSessionFactory();
}

The part I'm looking into is "CurrentSessionContext<>". I'd like to be able to set this based on the application that is calling it. Most of the time this library is accessed via web app, so the above works fine. However, recently I had a need to use this layer in a console application, where CallSessionContext seemed more appropriate.

Is it possible to pass an ICurrentSessionContext to be used in place?

I've tried something along the lines of:

public static ISessionFactory GetSessionConfiguration<ICurrentSessionContext>

or

public static ISessionFactory GetSessionConfiguration<TSessionContext>

but haven't had any luck just yet.

Any assistance is greatly appreciated!

+1  A: 

This is possible using "where constraints".

ie:

ISessionFactory GetSessionConfiguration<T> where T : ICurrentSessionContext

When called, this allows you to do the following:

SessionConfiguration.GetSessionConfiguration<CallSessionContext>();
Alexis Abril