Skip to content

New StaticProxyFactoryFactory #1451

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

Merged
merged 8 commits into from
Dec 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public void NotConfiguredProxyFactoryFactory()
{
var bcp = new BytecodeProviderImpl();
IProxyFactoryFactory p = bcp.ProxyFactoryFactory;
Assert.That(p, Is.InstanceOf<DefaultProxyFactoryFactory>());
Assert.That(p, Is.InstanceOf<StaticProxyFactoryFactory>());
}

[Test]
Expand Down
5 changes: 3 additions & 2 deletions src/NHibernate/Bytecode/AbstractBytecodeProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public virtual IProxyFactoryFactory ProxyFactoryFactory
throw new HibernateByteCodeException("Failed to create an instance of '" + proxyFactoryFactory.FullName + "'!", e);
}
}
return new DefaultProxyFactoryFactory();

return StaticProxyFactoryFactory.Instance;
}
}

Expand Down Expand Up @@ -116,4 +117,4 @@ public void SetCollectionTypeFactoryClass(System.Type type)

#endregion
}
}
}
17 changes: 17 additions & 0 deletions src/NHibernate/Bytecode/StaticProxyFactoryFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using NHibernate.Proxy;

namespace NHibernate.Bytecode
{
public class StaticProxyFactoryFactory : IProxyFactoryFactory
{
internal static StaticProxyFactoryFactory Instance = new StaticProxyFactoryFactory();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For enforcing the singleton pattern, I would define a private default constructor.

Copy link
Member Author

@hazzik hazzik Dec 12, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a small memory optimization. I don't want to enforce the singleton pattern here. And, in fact, we cannot enforce it, as StaticProxyFactoryFactory can be manually configured as a proxy factory factory and will require the public constructor to be creatable by reflection.

Copy link
Member

@fredericDelaporte fredericDelaporte Dec 12, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I forgot to think about configuration.


public IProxyFactory BuildProxyFactory() => new StaticProxyFactory();

public IProxyValidator ProxyValidator => new DynProxyTypeValidator();

public bool IsInstrumented(System.Type entityClass) => true;

public bool IsProxy(object entity) => entity is INHibernateProxy;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public DefaultyProxyMethodBuilder(IMethodBodyEmitter emitter)

public IMethodBodyEmitter MethodBodyEmitter { get; private set; }

private static MethodBuilder GenerateMethodSignature(string name, MethodInfo method, TypeBuilder typeBuilder)
internal static MethodBuilder GenerateMethodSignature(string name, MethodInfo method, TypeBuilder typeBuilder)
{
//TODO: Should we use attributes of base method?
var methodAttributes = MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.Virtual;
Expand Down
2 changes: 1 addition & 1 deletion src/NHibernate/Proxy/DynamicProxy/ProxyFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ private TypeInfo CreateUncachedProxyType(System.Type baseType, IReadOnlyCollecti
return proxyType;
}

private IEnumerable<MethodInfo> GetProxiableMethods(System.Type type, IEnumerable<System.Type> interfaces)
internal static IEnumerable<MethodInfo> GetProxiableMethods(System.Type type, IEnumerable<System.Type> interfaces)
{
const BindingFlags candidateMethodsBindingFlags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance;
return
Expand Down
17 changes: 17 additions & 0 deletions src/NHibernate/Proxy/LiteLazyInitializer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using NHibernate.Engine;

namespace NHibernate.Proxy
{
[Serializable]
internal sealed class LiteLazyInitializer : AbstractLazyInitializer
{
internal LiteLazyInitializer(string entityName, object id, ISessionImplementor session, System.Type persistentClass)
: base(entityName, id, session)
{
PersistentClass = persistentClass;
}

public override System.Type PersistentClass { get; }
}
}
Loading