-
Notifications
You must be signed in to change notification settings - Fork 33
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
Cannot inherit Database when targeting netcoreapp without using a shared DbConnection #64
Comments
Hey Q! I guess I hadn't thought of an inheritance scenario, and I don't mind making these changes, but the reason for the constructor mess in the first place was that .NET Core didn't support DbProviderFactories and related functionality at the time. They brought it back in 2.1 and I'm guessing you're targeting something newer than that, so I could just add back the old ctors for >= netcoreapp2.1:
Would that work? If you'd still rather have the ctor you suggested I'm good with that too. Might even make sense to make it protected to indicate that this is the right scenario to use it. Hell, I'm kind of inclined to just do both. |
Sure, that works. I might suggest that any constructors that are available publicly for netfx should also be publicly available for corefx, baring any missing functionality, but I don't have a strong opinion on that. A note for anyone who might be reading this later: to use the constructors that take a provider name or connection string name when targeting the core runtime requires explicitly registering In case it's helpful, here's how we use inheritance with
|
I agree. Missing functionality was the whole problem 2.5 years ago when I did this, but I gotta think most netcore apps today are on at least 2.1 so I'll add these back and it shouldn't be an issue. I'm thinking the one exception will be the one that takes
Good point, I forgot about that. That's a good argument for providing a public or protected ctor like the one you suggested originally. |
Probably don't need to worry much about people targeting core v1.0-2.0, and I agree the You could possibly target netcoreapp1.0, 1.1, and 2.0 and use those monikers as the compiler conditional to hide the connectionString constructors, but it might just be more hassle than it's worth - and I haven't tested if that even works as needed if you have say, Lib A targeting netstandard and referencing AsyncPoco used by App B targeting, say, netcoreapp2.0 and referencing Lib A (but not referencing AsyncPoco directly). v2.2 is the minimum I'm targeting, as I already have ASP.Net Core apps on that version (but targeting net472 currently) - 2.2 is just a brief stop to flush out issues between full framework and core runtime targeting before updating to 3.1. |
I'm smelling some breaking changes in the near future, maybe I'll just do this right and bump the lib to 3.0. :) The recommendation for cross-platform targeting in libraries these days is netstandard2.0 only. What sucks about that is it includes core 2.0 and yet protected Database(Type connectionType, string connectionString) {
if (!typeof(DbConnection).IsAssignableFrom(connectionType))
throw new ArgumentException(...);
...
} At least with that you don't need to register a provider factory. For 3.0 I'm starting to wonder if the object model should be simplified by making |
That also looks like it could work.. One thing I should mention is that I'm also trying to use Microsoft.Data.SqlClient over System.Data.SqlClient - the relevant area in AsyncPoco is With your As I write all this, though, and look at the source - I wonder was |
All good points. It was actually Guessing you need something in the near term to get unblocked? I think we have a couple options here, so maybe I'll just go with the path of least resistance for now and we can keep the dialog going on a possible 3.0. You probably know this but PetaPoco supports async now so AsyncPoco has sort of lost its only distinguishing feature and I certainly wouldn't fault anyone if they wanted to switch back. But, I'd also be happy to move this project forward and maybe 3.0 can get some new distinguishing features. Support for retry policies like you built perhaps? |
No rush, I have a reflection-based work-around for now, and it will probably be several weeks still before I'm fully through the rest of work to retarget for .Net Core. |
I inherit
Database
to override a handful of key methods to wrap them with retry policies.While retargeting my applications I notice that the only constructor available when targeting netcoreapp (any version) seems to be
Database(DbConnection connection)
and this treats the passed in connection as shared, forcing connection management back on the inheritor.Implementing the same retries by compositing
Database
, using the staticCreate
method to avoid a sharedDbConnection
, appears much more tedious.It would be very helpful if I could access the
private Database(DatabaseType dbType, Func<DbConnection> createConnection)
constructor; however, theDatabaseType
is internal.Perhaps this constructor could be added:
This would allow me to continue letting AsyncPoco handle connection lifetime while also continuing to allow me to effectively override
Database
methods when targeting the .Net Core runtime.I can work around this by setting
_connectionFactory
,_sharedConnection
, and_sharedConnectionDepth
through reflection in my inheriting class's constructor after calling thebase(DbConnection connection)
constructor, but a public, non-reflection-based method would be preferable.Thanks for all your hard work on this library!
The text was updated successfully, but these errors were encountered: