-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Expose IDbConnection through DI #2761
Conversation
…ression, had to hack it a little bit.
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.
That will be an issue. You will need to create a wrapper around the connection (implementing) idbconnection that will be built using the session. This way we can return it without asynchronous calls. Also, register this instance with the interface in the AddScoped call so it's a lazy initialization instead.
@sebastienros I am not sure what you mean? Why are we using async anyway just for a connection object? I (speaking as the end - developer trying to extend the data model) don't want an open connection nor a transaction. My Micro ORM / ORM will handle that or I will handle it explicitly in the module. I don't think is a good idea to open a connection without explicitly trying to read or update the data. So I looked at the DemandAsync() code and it turns out it is calling DBConnection.OpenAsync() that is the reason why it is async. However, I did find something in DemandAsync() that was exactly what I think I and other developers need.
So if I use the IStore instance to simply get the connection factory we get something like this:
I think it's all that really needed, and no async / await method Calls! |
You have a |
Agreed, I had read that wasn't a really good way to do things. If we simply use: We don't need to do async because all we need is the IDbConnection instance. |
It's not the issue. The issue is that someone will do It might be necessary to use a provider interface with a |
Didn't want to add this to pull request
@mdockal i re-added the .gitignore but without the added line directly in your repo, so that here we now have only one modified file. |
…entation. Registered IDbConnectionWrapper in OrchardCoreBuilderExtensions.AddDataAccess
I created an IDbConnectionAccessorr interface and DbConnectoinAccessor and registered it. The developer will call
|
Changed ArgumentExeption to ArgumentNullException
Cleaned up usings.
Cleaned up usings.
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.
Last details and it's all good.
src/OrchardCore/OrchardCore.Data.Abstractions/IDbConnectionWrapper.cs
Outdated
Show resolved
Hide resolved
src/OrchardCore/OrchardCore.Data.Abstractions/IDbConnectionWrapper.cs
Outdated
Show resolved
Hide resolved
…o OrchardCore.Data.Abstractions. Renamed DbConnectionWrapper to DbConnectionAccessor and added using for OrchardCore.Data.Abstractions
Fixes #2757, and fixes #2248. Ran into some issues with async /await inside lambda expression, had to hack it a little bit.