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
Decouple configuration of IObjectsFactory from BytecodeProvider #1758
Conversation
Actually, we need to add a configuration option to be able to configure the objects factory by xml. |
So, need to add something working the same way than the
First, better handle changes for this subject (if any) in another PR I think. Then, the So in fact, should the objects factory usage be restricted to things for which dependency injection could make sens? I think yes, since there is only the two above cases which use it for "newables", and only when these "newable" are structs.
Again, better address this in another PR. But I think we could obsolete this overload. The For the |
I've added it in the same way as the I agree with what you said @fredericDelaporte, I have the same thinking about how and when the |
Can you add a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am going to add another commit for updating the documentation. And maybe another one to avoid a breaking change.
Thinking about it, this PR is maybe only a first step. The objects factory receives as argument concrete types, which are to be configured through NHibernate settings. A next step (in another PR) could be to add a new setting telling NHibernate to use the objects factory directly on interface types, allowing for a true dependency injection logic to be put in place.
/// 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(); |
There was a problem hiding this comment.
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.
To be squashed
To be squashed
I have added maca88#2. |
Add doc and avoid a breaking change
UPD: But strangely enough, the |
There are definitely some more work to do with current objects factory usages, but anyway I was thinking dedicated PR were better for these related subjects. |
IObjectsFactory is meant for instantiating NHibernate dependencies, but it was used in some cases for instantiating value types. Some of its methods are also hard or impossible to implement with many dependency injection frameworks. Follow up to nhibernate#1758
IObjectsFactory is meant for instantiating NHibernate dependencies, but it was used in some cases for instantiating value types. Some of its methods are also hard or impossible to implement with many dependency injection frameworks. Follow up to nhibernate#1758
IObjectsFactory is meant for instantiating NHibernate dependencies, but it was used in some cases for instantiating value types. Some of its methods are also hard or impossible to implement with many dependency injection frameworks. Follow up to nhibernate#1758
IObjectsFactory is meant for instantiating NHibernate dependencies, but it was used in some cases for instantiating value types. Some of its methods are also hard or impossible to implement with many dependency injection frameworks. Follow up to nhibernate#1758
IObjectsFactory is meant for instantiating NHibernate dependencies, but it was used in some cases for instantiating value types. Some of its methods are also hard or impossible to implement with many dependency injection frameworks. Follow up to #1758
Here is a simple solution to configure
IObjectsFactory
separately fromIBytecodeProvider
, related issue. I know that having it configured statically is not the best solution, but the problem is that today,IObjectsFactory
is used by many static methods that are public. If we want this in5.2
, this is the only possible solution that I see.In addition, the
IObjectsFactory
has an overload with thenonPublic
parameter which is not possible to implement with most of the IoC containers. The overload is currently used in only two places (AliasToBeanResultTransformer and PocoInstantiator) and all tests passes when the second argument is removed. Wouldn't it be better to obsolete that overload and let the implementor decide whether to use a non public constructor?Even the overload with the
ctorArgs
is not possible to implement with some IoC containers as it is considered as a code smell. This overload is also used only two times, one time in SessionFactoryImpl which is not that easy to change because of the circular dependency betweenICurrentSessionContext
andISessionFactory
and the second in SchemaExport which is quite strange as the ScriptSplitter does not have any virtual members.Fixes #1671