Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion src/NHibernate.Test/NHSpecificTest/GH1547/Fixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public partial class DriverForSubstitutedCommand : IDriver

public DriverForSubstitutedCommand()
{
_driverImplementation = (IDriver) Cfg.Environment.BytecodeProvider.ObjectsFactory.CreateInstance(DriverClass);
_driverImplementation = (IDriver) Cfg.Environment.ObjectsFactory.CreateInstance(DriverClass);
}

DbCommand IDriver.GenerateCommand(CommandType type, SqlString sqlString, SqlType[] parameterTypes)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ public class ClientDriverWithParamsStats : IDriver

public ClientDriverWithParamsStats()
{
_driverImplementation = (IDriver) Cfg.Environment.BytecodeProvider.ObjectsFactory.CreateInstance(DriverClass);
_driverImplementation = (IDriver) Cfg.Environment.ObjectsFactory.CreateInstance(DriverClass);
}

private static void Inc<T>(T type, IDictionary<T, int> dic)
Expand Down
2 changes: 1 addition & 1 deletion src/NHibernate/Async/Tool/hbm2ddl/SchemaExport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ private async Task ExecuteInitializedAsync(Action<string> scriptAction, bool exe
cancellationToken.ThrowIfCancellationRequested();
if (dialect.SupportsSqlBatches)
{
var objFactory = Environment.BytecodeProvider.ObjectsFactory;
var objFactory = Environment.ObjectsFactory;
ScriptSplitter splitter = (ScriptSplitter)objFactory.CreateInstance(typeof(ScriptSplitter), sql);

foreach (string stmt in splitter)
Expand Down
2 changes: 1 addition & 1 deletion src/NHibernate/Async/Tool/hbm2ddl/SchemaUpdate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public partial class SchemaUpdate
{
cfg.SetNamingStrategy(
(INamingStrategy)
Environment.BytecodeProvider.ObjectsFactory.CreateInstance(ReflectHelper.ClassForName(args[i].Substring(9))));
Environment.ObjectsFactory.CreateInstance(ReflectHelper.ClassForName(args[i].Substring(9))));
}
}
else
Expand Down
2 changes: 1 addition & 1 deletion src/NHibernate/Async/Tool/hbm2ddl/SchemaValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public partial class SchemaValidator
{
cfg.SetNamingStrategy(
(INamingStrategy)
Cfg.Environment.BytecodeProvider.ObjectsFactory.CreateInstance(ReflectHelper.ClassForName(args[i].Substring(9))));
Cfg.Environment.ObjectsFactory.CreateInstance(ReflectHelper.ClassForName(args[i].Substring(9))));
}
}
else
Expand Down
12 changes: 5 additions & 7 deletions src/NHibernate/Bytecode/AbstractBytecodeProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ namespace NHibernate.Bytecode
{
public abstract class AbstractBytecodeProvider : IBytecodeProvider, IInjectableProxyFactoryFactory, IInjectableCollectionTypeFactoryClass
{
private readonly IObjectsFactory objectsFactory = new ActivatorObjectsFactory();
protected System.Type proxyFactoryFactory;
private ICollectionTypeFactory collectionTypeFactory;
private System.Type collectionTypeFactoryClass = typeof(Type.DefaultCollectionTypeFactory);
Expand All @@ -21,7 +20,7 @@ public virtual IProxyFactoryFactory ProxyFactoryFactory
{
try
{
return (IProxyFactoryFactory) ObjectsFactory.CreateInstance(proxyFactoryFactory);
return (IProxyFactoryFactory) Cfg.Environment.ObjectsFactory.CreateInstance(proxyFactoryFactory);
}
catch (Exception e)
{
Expand All @@ -35,10 +34,9 @@ public virtual IProxyFactoryFactory ProxyFactoryFactory

public abstract IReflectionOptimizer GetReflectionOptimizer(System.Type clazz, IGetter[] getters, ISetter[] setters);

public virtual IObjectsFactory ObjectsFactory
{
get { return objectsFactory; }
}
// Since 5.2
[Obsolete("Please use NHibernate.Cfg.Environment.ObjectsFactory instead")]
public virtual IObjectsFactory ObjectsFactory => Cfg.Environment.ObjectsFactory;

public virtual ICollectionTypeFactory CollectionTypeFactory
{
Expand All @@ -49,7 +47,7 @@ public virtual ICollectionTypeFactory CollectionTypeFactory
try
{
collectionTypeFactory =
(ICollectionTypeFactory) ObjectsFactory.CreateInstance(collectionTypeFactoryClass);
(ICollectionTypeFactory) Cfg.Environment.ObjectsFactory.CreateInstance(collectionTypeFactoryClass);
}
catch (Exception e)
{
Expand Down
3 changes: 3 additions & 0 deletions src/NHibernate/Bytecode/IBytecodeProvider.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using NHibernate.Properties;

namespace NHibernate.Bytecode
Expand Down Expand Up @@ -26,6 +27,8 @@ public interface IBytecodeProvider
/// <remarks>
/// For entities <see cref="IReflectionOptimizer"/> and its implementations.
/// </remarks>
// Since 5.2
[Obsolete("Please use NHibernate.Cfg.Environment.ObjectsFactory instead")]
IObjectsFactory ObjectsFactory { get; }

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion src/NHibernate/Cfg/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1902,7 +1902,7 @@ public void SetListeners(ListenerType type, string[] listenerClasses)
{
try
{
listeners[i] = Environment.BytecodeProvider.ObjectsFactory.CreateInstance(ReflectHelper.ClassForName(listenerClasses[i]));
listeners[i] = Environment.ObjectsFactory.CreateInstance(ReflectHelper.ClassForName(listenerClasses[i]));
}
catch (Exception e)
{
Expand Down
10 changes: 10 additions & 0 deletions src/NHibernate/Cfg/Environment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,16 @@ public static IBytecodeProvider BytecodeProvider
set { BytecodeProviderInstance = value; }
}

/// <summary>
/// NHibernate's object instantiator.
/// </summary>
/// <remarks>
/// This should only be set before a configuration object
/// is created, otherwise the change may not take effect.
/// For entities see <see cref="IReflectionOptimizer"/> and its implementations.
/// </remarks>
public static IObjectsFactory ObjectsFactory { get; set; } = new ActivatorObjectsFactory();
Copy link
Member

Choose a reason for hiding this comment

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

To avoid a possible breaking change, we should default to using BytecodeProvider.ObjectsFactory here. But for completeness, we should also use the objects factory to create the byte-code provider...

I may add a commit sorting this out.


/// <summary>
/// Whether to enable the use of reflection optimizer
/// </summary>
Expand Down
12 changes: 6 additions & 6 deletions src/NHibernate/Cfg/SettingsFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ public Settings BuildSettings(IDictionary<string, string> properties)
{
settings.QueryCacheFactory =
(IQueryCacheFactory)
Environment.BytecodeProvider.ObjectsFactory.CreateInstance(ReflectHelper.ClassForName(queryCacheFactoryClassName));
Environment.ObjectsFactory.CreateInstance(ReflectHelper.ClassForName(queryCacheFactoryClassName));
}
catch (Exception cnfe)
{
Expand Down Expand Up @@ -331,7 +331,7 @@ private static IBatcherFactory CreateBatcherFactory(IDictionary<string, string>
log.Info("Batcher factory: {0}", tBatcher.AssemblyQualifiedName);
try
{
return (IBatcherFactory) Environment.BytecodeProvider.ObjectsFactory.CreateInstance(tBatcher);
return (IBatcherFactory) Environment.ObjectsFactory.CreateInstance(tBatcher);
}
catch (Exception cnfe)
{
Expand All @@ -352,7 +352,7 @@ private static ICacheProvider CreateCacheProvider(IDictionary<string, string> pr
{
return
(ICacheProvider)
Environment.BytecodeProvider.ObjectsFactory.CreateInstance(ReflectHelper.ClassForName(cacheClassName));
Environment.ObjectsFactory.CreateInstance(ReflectHelper.ClassForName(cacheClassName));
}
catch (Exception e)
{
Expand All @@ -370,7 +370,7 @@ private static IQueryTranslatorFactory CreateQueryTranslatorFactory(IDictionary<
{
return
(IQueryTranslatorFactory)
Environment.BytecodeProvider.ObjectsFactory.CreateInstance(ReflectHelper.ClassForName(className));
Environment.ObjectsFactory.CreateInstance(ReflectHelper.ClassForName(className));
}
catch (Exception cnfe)
{
Expand Down Expand Up @@ -403,7 +403,7 @@ private static ITransactionFactory CreateTransactionFactory(IDictionary<string,
{
var transactionFactory =
(ITransactionFactory)
Environment.BytecodeProvider.ObjectsFactory.CreateInstance(ReflectHelper.ClassForName(className));
Environment.ObjectsFactory.CreateInstance(ReflectHelper.ClassForName(className));
transactionFactory.Configure(properties);
return transactionFactory;
}
Expand All @@ -426,7 +426,7 @@ private static IQueryModelRewriterFactory CreateQueryModelRewriterFactory(IDicti
{
return
(IQueryModelRewriterFactory)
Environment.BytecodeProvider.ObjectsFactory.CreateInstance(ReflectHelper.ClassForName(className));
Environment.ObjectsFactory.CreateInstance(ReflectHelper.ClassForName(className));
}
catch (Exception cnfe)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private static IAuxiliaryDatabaseObject CreateCustomObject(Mappings mappings, Hb
System.Type customType = ReflectHelper.ClassForName(className);

IAuxiliaryDatabaseObject customObject =
(IAuxiliaryDatabaseObject) Environment.BytecodeProvider.ObjectsFactory.CreateInstance(customType);
(IAuxiliaryDatabaseObject) Environment.ObjectsFactory.CreateInstance(customType);

foreach (string dialectName in databaseObjectSchema.FindDialectScopeNames())
{
Expand Down
2 changes: 1 addition & 1 deletion src/NHibernate/Connection/ConnectionProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ protected virtual void ConfigureDriver(IDictionary<string, string> settings)
try
{
driver =
(IDriver) Environment.BytecodeProvider.ObjectsFactory.CreateInstance(ReflectHelper.ClassForName(driverClass));
(IDriver) Environment.ObjectsFactory.CreateInstance(ReflectHelper.ClassForName(driverClass));
driver.Configure(settings);
}
catch (Exception e)
Expand Down
2 changes: 1 addition & 1 deletion src/NHibernate/Connection/ConnectionProviderFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static IConnectionProvider NewConnectionProvider(IDictionary<string, stri
log.Info("Initializing connection provider: {0}", providerClass);
connections =
(IConnectionProvider)
Environment.BytecodeProvider.ObjectsFactory.CreateInstance(ReflectHelper.ClassForName(providerClass));
Environment.ObjectsFactory.CreateInstance(ReflectHelper.ClassForName(providerClass));
}
catch (Exception e)
{
Expand Down
2 changes: 1 addition & 1 deletion src/NHibernate/Dialect/Dialect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ private static Dialect InstantiateDialect(string dialectName, IDictionary<string
{
try
{
var dialect = (Dialect)Environment.BytecodeProvider.ObjectsFactory.CreateInstance(ReflectHelper.ClassForName(dialectName));
var dialect = (Dialect)Environment.ObjectsFactory.CreateInstance(ReflectHelper.ClassForName(dialectName));
dialect.Configure(props);
return dialect;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ public ReflectionDriveConnectionCommandProvider(System.Type connectionType, Syst

public DbConnection CreateConnection()
{
return (DbConnection) Environment.BytecodeProvider.ObjectsFactory.CreateInstance(connectionType);
return (DbConnection) Environment.ObjectsFactory.CreateInstance(connectionType);
}

public DbCommand CreateCommand()
{
return (DbCommand) Environment.BytecodeProvider.ObjectsFactory.CreateInstance(commandType);
return (DbCommand) Environment.ObjectsFactory.CreateInstance(commandType);
}

#endregion
Expand Down
2 changes: 1 addition & 1 deletion src/NHibernate/Exceptions/SQLExceptionConverterFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ private static ISQLExceptionConverter ConstructConverter(string converterClassNa
}

// Otherwise, try to use the no-arg constructor
return (ISQLExceptionConverter) Cfg.Environment.BytecodeProvider.ObjectsFactory.CreateInstance(converterClass);
return (ISQLExceptionConverter) Cfg.Environment.ObjectsFactory.CreateInstance(converterClass);
}
catch (Exception t)
{
Expand Down
2 changes: 1 addition & 1 deletion src/NHibernate/Id/IdentifierGeneratorFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public static IIdentifierGenerator Create(string strategy, IType type, IDictiona
try
{
System.Type clazz = GetIdentifierGeneratorClass(strategy, dialect);
var idgen = (IIdentifierGenerator) Cfg.Environment.BytecodeProvider.ObjectsFactory.CreateInstance(clazz);
var idgen = (IIdentifierGenerator) Cfg.Environment.ObjectsFactory.CreateInstance(clazz);
var conf = idgen as IConfigurable;
if (conf != null)
{
Expand Down
2 changes: 1 addition & 1 deletion src/NHibernate/Impl/SessionFactoryImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1283,7 +1283,7 @@ private ICurrentSessionContext BuildCurrentSessionContext()
{
System.Type implClass = ReflectHelper.ClassForName(impl);
return
(ICurrentSessionContext)Environment.BytecodeProvider.ObjectsFactory.CreateInstance(implClass, new object[] { this });
(ICurrentSessionContext)Environment.ObjectsFactory.CreateInstance(implClass, new object[] { this });
}
catch (Exception e)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static ILinqToHqlGeneratorsRegistry CreateGeneratorsRegistry(IDictionary<
try
{
log.Info("Initializing LinqToHqlGeneratorsRegistry: {0}", registry);
return (ILinqToHqlGeneratorsRegistry) Environment.BytecodeProvider.ObjectsFactory.CreateInstance(ReflectHelper.ClassForName(registry));
return (ILinqToHqlGeneratorsRegistry) Environment.ObjectsFactory.CreateInstance(ReflectHelper.ClassForName(registry));
}
catch (Exception e)
{
Expand Down
2 changes: 1 addition & 1 deletion src/NHibernate/Mapping/Collection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public object Comparer
{
try
{
comparer = Cfg.Environment.BytecodeProvider.ObjectsFactory.CreateInstance(ReflectHelper.ClassForName(ComparerClassName));
comparer = Cfg.Environment.ObjectsFactory.CreateInstance(ReflectHelper.ClassForName(ComparerClassName));
}
catch (Exception ex)
{
Expand Down
2 changes: 1 addition & 1 deletion src/NHibernate/Properties/PropertyAccessorFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ private static IPropertyAccessor ResolveCustomAccessor(string accessorName)

try
{
var result = (IPropertyAccessor) Cfg.Environment.BytecodeProvider.ObjectsFactory.CreateInstance(accessorClass);
var result = (IPropertyAccessor) Cfg.Environment.ObjectsFactory.CreateInstance(accessorClass);
accessors[accessorName] = result;
return result;
}
Expand Down
2 changes: 1 addition & 1 deletion src/NHibernate/Tool/hbm2ddl/SchemaExport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ private void ExecuteSql(DbCommand cmd, string sql)
{
if (dialect.SupportsSqlBatches)
{
var objFactory = Environment.BytecodeProvider.ObjectsFactory;
var objFactory = Environment.ObjectsFactory;
ScriptSplitter splitter = (ScriptSplitter)objFactory.CreateInstance(typeof(ScriptSplitter), sql);

foreach (string stmt in splitter)
Expand Down
2 changes: 1 addition & 1 deletion src/NHibernate/Tool/hbm2ddl/SchemaUpdate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public static void Main(string[] args)
{
cfg.SetNamingStrategy(
(INamingStrategy)
Environment.BytecodeProvider.ObjectsFactory.CreateInstance(ReflectHelper.ClassForName(args[i].Substring(9))));
Environment.ObjectsFactory.CreateInstance(ReflectHelper.ClassForName(args[i].Substring(9))));
}
}
else
Expand Down
2 changes: 1 addition & 1 deletion src/NHibernate/Tool/hbm2ddl/SchemaValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static void Main(string[] args)
{
cfg.SetNamingStrategy(
(INamingStrategy)
Cfg.Environment.BytecodeProvider.ObjectsFactory.CreateInstance(ReflectHelper.ClassForName(args[i].Substring(9))));
Cfg.Environment.ObjectsFactory.CreateInstance(ReflectHelper.ClassForName(args[i].Substring(9))));
}
}
else
Expand Down
2 changes: 1 addition & 1 deletion src/NHibernate/Transform/AliasToBeanResultTransformer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public override object TransformTuple(object[] tuple, String[] aliases)
{
result = _resultClass.IsClass
? _beanConstructor.Invoke(null)
: Cfg.Environment.BytecodeProvider.ObjectsFactory.CreateInstance(_resultClass, true);
: Cfg.Environment.ObjectsFactory.CreateInstance(_resultClass, true);

for (int i = 0; i < aliases.Length; i++)
{
Expand Down
2 changes: 1 addition & 1 deletion src/NHibernate/Tuple/PocoInstantiator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ private object GetInstance()
}
if (mappedClass.IsValueType)
{
return Cfg.Environment.BytecodeProvider.ObjectsFactory.CreateInstance(mappedClass, true);
return Cfg.Environment.ObjectsFactory.CreateInstance(mappedClass, true);
}
if (constructor == null)
{
Expand Down
2 changes: 1 addition & 1 deletion src/NHibernate/Type/CompositeCustomType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public CompositeCustomType(System.Type userTypeClass, IDictionary<string, string

try
{
userType = (ICompositeUserType) Cfg.Environment.BytecodeProvider.ObjectsFactory.CreateInstance(userTypeClass);
userType = (ICompositeUserType) Cfg.Environment.ObjectsFactory.CreateInstance(userTypeClass);
}
catch (MethodAccessException mae)
{
Expand Down
2 changes: 1 addition & 1 deletion src/NHibernate/Type/CustomCollectionType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public CustomCollectionType(System.Type userTypeClass, string role, string forei

try
{
userType = (IUserCollectionType) Cfg.Environment.BytecodeProvider.ObjectsFactory.CreateInstance(userTypeClass);
userType = (IUserCollectionType) Cfg.Environment.ObjectsFactory.CreateInstance(userTypeClass);
}
catch (InstantiationException ie)
{
Expand Down
2 changes: 1 addition & 1 deletion src/NHibernate/Type/CustomType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public CustomType(System.Type userTypeClass, IDictionary<string, string> paramet

try
{
userType = (IUserType) Cfg.Environment.BytecodeProvider.ObjectsFactory.CreateInstance(userTypeClass);
userType = (IUserType) Cfg.Environment.ObjectsFactory.CreateInstance(userTypeClass);
}
catch (ArgumentNullException ane)
{
Expand Down
2 changes: 1 addition & 1 deletion src/NHibernate/Type/TypeFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ public static IType HeuristicType(string typeName, IDictionary<string, string> p
{
try
{
type = (IType) Environment.BytecodeProvider.ObjectsFactory.CreateInstance(typeClass);
type = (IType) Environment.ObjectsFactory.CreateInstance(typeClass);
}
catch (Exception e)
{
Expand Down