Skip to content

Commit 009648f

Browse files
fixup! Clean-up IObjectsFactory usages
Use session context creation logic from @hazzik Co-authored-by: Alexander Zaytsev <[email protected]>
1 parent 37c9abb commit 009648f

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/NHibernate/Impl/SessionFactoryImpl.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,14 +1282,20 @@ private ICurrentSessionContext BuildCurrentSessionContext()
12821282
try
12831283
{
12841284
var implClass = ReflectHelper.ClassForName(impl);
1285-
if (!typeof(ISessionFactoryAwareCurrentSessionContext).IsAssignableFrom(implClass))
1285+
var constructor = implClass.GetConstructor(new [] { typeof(ISessionFactoryImplementor) });
1286+
ICurrentSessionContext context;
1287+
if (constructor != null)
12861288
{
1287-
return (ICurrentSessionContext) Activator.CreateInstance(implClass, this);
1289+
context = (ICurrentSessionContext) constructor.Invoke(new object[] { this });
1290+
}
1291+
else
1292+
{
1293+
context = (ICurrentSessionContext) Environment.ObjectsFactory.CreateInstance(implClass);
1294+
}
1295+
if (context is ISessionFactoryAwareCurrentSessionContext sessionFactoryAwareContext)
1296+
{
1297+
sessionFactoryAwareContext.SetFactory(this);
12881298
}
1289-
1290-
var context = (ISessionFactoryAwareCurrentSessionContext) Environment.ObjectsFactory.CreateInstance(implClass);
1291-
context.SetFactory(this);
1292-
return context;
12931299
}
12941300
catch (Exception e)
12951301
{

0 commit comments

Comments
 (0)