c # – Using DbConnection as a property with only get or as

I have a disposable class that includes the connection to the database and the memory cache client.

My class will have data. First, it will look at the cache for the data. If the cache is empty, it will get the data from the database and cache it.

I do not want to open a connection to the database until it is necessary. However, I am not sure if I connect db as a property, the connection will not be open until I call it.

I show two options in the code example below. Let me know which one would be best and why?

Public class ViewContentModel: IDisposable
{
#region get an alternative
virtual public IDbConnectionFactory DbFactory
{
get {return HostContext.TryResolve(); }
}
private IDbConnection db;
Db IDbVirtual Virtual Connection
{
get {back db ?? (db = DbFactory.OpenDbConnection ()); }
}
#endregion
Alternative method by region

private IDbConnection db;
Db IDbVirtual Virtual Connection ()
{
if (db! = null)
return db;
var DbFactory = HostContext.TryResolve();
return db = DbFactory.OpenDbConnection ();
}
#endregion



private ICacheClient cache;
cache ICacheClient virtual public
{
get {back cache ?? (cache = HostContext.TryResolve()); }
}
empty virtual public Dispose ()
{
if (db! = null)
db.Dispose ();
}
}