Hangfire and idbconnection

I’m curious how folks are handling idbconnection with ormlite, wether your injecting it directly or have another class that holds the factory and ask for a connection…

Any feedback is appreciated

Unless you know about the lifecycle of where the connection is used, the safest approach that works everywhere would be to inject the ThreadSafe IDbConnectionFactory that’s used to open DB Connections within a using {} statement so it’s disposed (and returned to the pool) immediately after use.

I was trying to use a class since we have a class based api that’s using ormlite as well, the goal was to let autofac deal with disposing the connections through the class so that hangfire jobs and the api could use the same connection (obviously in the same thread). Which would facilitate starting a transaction and making a bunch of calls in both the api and within the job all on the same connection.

This looks like probably the cleanest pattern…