-
Notifications
You must be signed in to change notification settings - Fork 933
Clean-up IObjectsFactory usages #1781
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ed9102c
4adf041
37c9abb
009648f
647c39e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using NHibernate.Cfg; | ||
using NHibernate.Context; | ||
using NHibernate.Engine; | ||
using NUnit.Framework; | ||
|
||
namespace NHibernate.Test.ConnectionTest | ||
{ | ||
[TestFixture] | ||
public class CustomCurrentSessionTest : ConnectionManagementTestCase | ||
{ | ||
protected override ISession GetSessionUnderTest() | ||
{ | ||
var session = OpenSession(); | ||
CustomContext.Session = session; | ||
return session; | ||
} | ||
|
||
protected override void Configure(Configuration configuration) | ||
{ | ||
base.Configure(cfg); | ||
cfg.SetProperty(Environment.CurrentSessionContextClass, typeof(CustomContext).AssemblyQualifiedName); | ||
} | ||
|
||
protected override void Release(ISession session) | ||
{ | ||
CustomContext.Session = null; | ||
base.Release(session); | ||
} | ||
|
||
[Test] | ||
public void ContextIsSetup() | ||
{ | ||
Assert.That(Sfi.CurrentSessionContext, Is.InstanceOf<CustomContext>()); | ||
Assert.That( | ||
((CustomContext) Sfi.CurrentSessionContext).Factory, | ||
Is.SameAs(((DebugSessionFactory) Sfi).ActualFactory)); | ||
} | ||
} | ||
|
||
public class CustomContext : ISessionFactoryAwareCurrentSessionContext | ||
{ | ||
internal ISessionFactoryImplementor Factory; | ||
internal static ISession Session; | ||
|
||
public ISession CurrentSession() | ||
{ | ||
return Session; | ||
} | ||
|
||
public void SetFactory(ISessionFactoryImplementor factory) | ||
{ | ||
Factory = factory; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,4 +76,4 @@ protected override void SetMap(IDictionary value) | |
_map = value; | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,4 +88,4 @@ public static bool HasBind() | |
return context != null && context.ContainsKey(me.factory); | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,4 +30,4 @@ protected override ISession Session | |
set => _session.Value = value; | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -203,10 +203,7 @@ private void ExecuteSql(DbCommand cmd, string sql) | |
{ | ||
if (dialect.SupportsSqlBatches) | ||
{ | ||
var objFactory = Environment.ObjectsFactory; | ||
ScriptSplitter splitter = (ScriptSplitter)objFactory.CreateInstance(typeof(ScriptSplitter), sql); | ||
|
||
foreach (string stmt in splitter) | ||
foreach (var stmt in new ScriptSplitter(sql)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As discussed on #1758, the |
||
{ | ||
log.Debug("SQL Batch: {0}", stmt); | ||
cmd.CommandText = stmt; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,7 +85,7 @@ public override object TransformTuple(object[] tuple, String[] aliases) | |
{ | ||
result = _resultClass.IsClass | ||
? _beanConstructor.Invoke(null) | ||
: Cfg.Environment.ObjectsFactory.CreateInstance(_resultClass, true); | ||
: Activator.CreateInstance(_resultClass, true); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As discussed in #1758, this usage is not a dependency but a DTO instantiation. If the user wants some custom behavior for instantiating value types, he now would have to provide its own transformer. |
||
|
||
for (int i = 0; i < aliases.Length; i++) | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,7 +103,7 @@ private object GetInstance() | |
} | ||
if (mappedClass.IsValueType) | ||
{ | ||
return Cfg.Environment.ObjectsFactory.CreateInstance(mappedClass, true); | ||
return Activator.CreateInstance(mappedClass, true); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As discussed in #1758, this usage is not a dependency but an entity instantiation. If the user wants some custom behavior for instantiating value types, he now would have to provide its own tuplizer. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think that the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably in some partial trust or similar environments. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have just preferred to be quite conservative, inlining the default previous implementation "as is". |
||
} | ||
if (constructor == null) | ||
{ | ||
|
Uh oh!
There was an error while loading. Please reload this page.