Is it possible to ensure that every developer in a VS project that uses a certain method (which returns Nhibernate session) will be enforced the using pattern. For example:
public static ISession GetSession()
{
ISessionFactory holder = ActiveRecordMediator.GetSessionFactoryHolder();
ISessionScope activeScope = holder.ThreadScopeInfo.GetRegisteredScope();
ISession session = null;
var key = holder.GetSessionFactory(typeof(ActiveRecordBase));
if (activeScope == null)
{
session = holder.CreateSession(typeof(ActiveRecordBase));
}
return session;
}
I want to ensure that every developer that calls this method surrounds it with the using statement, otherwise it will be treated as an error by Visual Studio and will not compile. (Or maybe by some tool that analyze managed code).
Must be used only as follows:
using (var session = Nh.GetSession())
{
//use the session
}