-
Notifications
You must be signed in to change notification settings - Fork 934
WIP - Replace IObjectsFactory with IServiceProvider interface #1793
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
base: master
Are you sure you want to change the base?
Conversation
{ | ||
using System.Threading.Tasks; | ||
[TestFixture] | ||
public class SettingsFactoryFixtureAsync |
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.
This class should not be generated as there is nothing async, it is a bug related to async generator that I need to fix.
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 released a new version of the async generator (0.8.2.10
) that fixes the issue of generating non async methods.
Let's hold-on on this for a moment. The PR is a good starting point, but, I think, we need to discuss what we want to achieve and what direction shall we go. |
The aim of this PR is to achieve the ability to configure services like
With #1781 the |
c96e233
to
4aca182
Compare
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 have rebased this on master by the way.
src/NHibernate/Linq/Functions/LinqToHqlGeneratorsRegistryFactory.cs
Outdated
Show resolved
Hide resolved
Fix dropped line
Refactor many instantiations
Remove undue warning deactivation
Avoid a possible breaking change
Avoid corrupting following tests in case of failure
Keep tests for an obsolete class, till it gets dropped
Fix regression: must use GetService instead of GetInstance for ICurrentSessionContext, since it is optional and GetInstance does not support it.
Throw explicitly on an error case.
Here is a series of fix proposals addressing my review comments. |
While looking into this, I have spotted a number of cases which will not play nice with dependency injection, due to not using the service provider, or forcing a default concrete class:
We should likely rework those cases too, probably in a dedicated PR. |
@fredericDelaporte thanks for fixing the mentioned issues, I am ok with them. |
Hi all. I think the registration/container building logic should not be there. |
… to ActivatorServiceProvider
I've removed the registration logic and renamed the class to |
Was thinking about this approach and found it might be inconvenient for an end user. For example, using other service provider other than supplied, an IoC/DI container which requires explicit components registration, for example, would require the user to register all NH services. I don't think that this is a desired behaviour. I think we need to have some fallback mechanism, eg fallback to I don't want to bring additional dependencies (eg |
I didn't known that some IoC containers like
Yes, I also think that we should add a fallback mechanism that should try to instantiate concrete types with |
|
…requires an explicit registration for concrete types
eb6e0e9
to
b256937
Compare
@hazzik, do you agree for merging or do you wish to have another look yourself before? |
I'll take another look. |
Postponing this to 5.3 is quite unfortunate. This PR changes public interfaces which were not yet released. Delaying it will cause more breaking changes to dodge, and more members to flag as obsolete, instead of just dropping them directly. |
Which exact interface are you talking about? |
I am talking about "interface" in its broad meaning, not just the technical C#
|
I do not want this to go into an opposite direction of #1781 but rather in the same and add value rather than replace. What it means is that, in my mind, it would be better if |
I do not see it as going into an opposite direction. For me, it is instead the same direction: removing specificities hindering dependency injection. I do neither see where is the added value in keeping an I see a value for the case of Microsoft The only value, that It will also allow users to directly use any dependency injection framework supporting In my view, if |
Switched to WIP: since 5.2 has been released, this PR has now binary breaking changes. |
@fredericDelaporte , @hazzik and @maca88 , This is something very important to embrace MS DI Abstractions and be conformant |
Here is an attempt to replace the
IObjectsFactory
withIServiceProvider
interface based on #1781.As discussed, with
IServiceProvider
we can get the service by the base type or interface without worrying whether the service is registered or not as it is designed to returnnull
in case the service is not registered. I've added a defaultIServiceProvier
implementation that has also the ability to register services in case the user does not use any IoC container and wants to pass a service instance. In addition, an additional methodPropertiesHelper.GetInstance
was added in order to be used by other NHibernate projects when instantiating a service via configuration properties.