codeapologist / dataabstractions.dapper Goto Github PK
View Code? Open in Web Editor NEWA light abstraction around Dapper and Dapper.Contrib that also maintains the behavior IDbConnection.
License: MIT License
A light abstraction around Dapper and Dapper.Contrib that also maintains the behavior IDbConnection.
License: MIT License
Is there any way you could add a mockable interface to replace the IDataReader, returned by ExecuteReader methods?
There are more extension methods applied to this type by the source Dapper library.
For instance, below:
return dataReader.Parse<T>();
where dataReader is an IDataReader
Parse is an extension method defined by dapper
We currently use this library to be able to unit test our repository classes but now we are in a situation where we are not utilising connection pooling properly because the connection is already created (and injected) when the repository is invoked, you cannot use the normal using
syntax when creating a connection inside an individual method.
I can't think of the correct pattern:
Use the normal using ( var connection = new DataAccessor(...) )
which disposes and pools correctly but prevents constructor injection being possible so unit tests won't work.
Inject IDataAccessor into the constructor as we currently do. This allows unit tests but does not permit the use of using, which means we should probably open the connection in the constructor and ensure our DI services are created in a liftetime scope so they don't tie up the connection for too long.
Inject the IDataAccessor into the constructor but don't open it and then in every method, call Open() and Close(). This would generate more code but would ensure we are not holding onto connections and not opening the connection if we don't need it (since we are using EF for some parts of the repositories)
Have constructor overloads one that takes IDataAccessor for unit tests and one that doesn't but then how would a method use the correct connection e.g. if the shared conn from the unit tests is available, use that, otherwise use the using
syntax. This sounds messy.
Do you have any ideas? Thanks.
Hello,
can QueryMultiple return something like IGridReader so it can be mocked? :)
thanks
Are you planning to update this NuGet package to the latest version of Dapper?
Please correct me if I am wrong, you are restricting the developer to use Microsoft provided DbConnections. In my case I am using an OracleConnection which is provided by Oracle and implements IDbConnection. I suppose you can change constructor signature to take an IDbConnection.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.