DapperLib / DapperLib/Dapper

Add ability to pass additional TypeHandlers to Query methods

Open
#1,587 1 comment 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C#
Stars
18.4k
Forks
3.7k
Avg merge
5h 8m
Merged PRs (30d)
1

Description

We are currently refactoring a massive platform that we inherited from another company, and as part of that we are removing EF and updating it to use Dapper. Whilst doing so, we have found a major 'chicken & egg' problem caused by the fact that the TypeHandlers collection is a global static collection while trying to move some collections over to Dapper whilst maintaining compatibility with EF for other parts of the platform that we cannot yet fully refactor.

We have types that we would like to handle via a TypeHandler because there are occasions where the value is returned as a value that we then have to "decode" to get the entity, but when we register it, it causes problems elsewhere in the code that cannot use that TypeHandler because the entity is returned as a datatable.

We cannot remove the TypeHandler for just these calls because it's a static collection and breaks the calls to the methods that require them, and calls that could require the TypeHandler could be occurring in parallel on other threads (which is exactly what we are seeing).

It would seem a logical solution to allow the Query...Async methods to pass in a list of additional TypeHandlers to allow on a per-query basis where registration of those TypeHandlers globally would cause issues.

Either that, or a mechanism to allow a TypeHandler to return something indicating that "I can't handle this" (or throw a custom Exception that can be caught by Dapper to signify the TypeHandler doesn't know how to handle what it's been given), and allow the default DataTable type handler to take over instead.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by examining the Query...Async methods and the global TypeHandlers collection described in the issue. Compare the proposed per-query handlers with the fallback DataTable behavior; done means a clear, thread-safe mechanism is defined and covered for both handler and non-handler queries.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
backend, database
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.