How to use Auto Interface Implementation
keerthirajap opened this issue · comments
Hi Team,
You are doing great job. Insight database saves/reduces lot of coding in DAL layers.
I have a question on using the Auto Interface Implementation.
Will below code open close the SQL connection automatically?, I have set the DB connection at Service Class constructor?
Please advice.
My BAL Class
public class AppAnalyticsService : IAppAnalyticsService
{
private IAppAnalyticsRepository _IAppAnalyticsRepository;
public AppAnalyticsService()
{
SqlInsightDbProvider.RegisterProvider();
string sqlConnection = Caching.Instance.GetApplicationConfigs("DBConnection");
DbConnection c = new SqlConnection(sqlConnection);
_IAppAnalyticsRepository = c.As<IAppAnalyticsRepository>();
}
public Int32 UpdatedUserDisConnectionTracking(IpPropertiesModal ipAddressDetails)
{
return this._IAppAnalyticsRepository.UpdatedUserDisConnectionTracking(ipAddressDetails);
}
}
My Repository
public interface IAppAnalyticsRepository : IDisposable
{
[Sql("P_SaveIpAddressDetailsOnLogin")]
Int32 SaveIpAddressDetailsOnLogin(IpPropertiesModal IpAddressDetails);
}
The behavior of connections is documented here:
https://github.com/jonwagner/Insight.Database/wiki/Auto-Open
As for interfaces, it works the same way. When you make a method call:
- If the connection is closed, the connection is automatically opened for the method call, then closed when it returns.
- If the connection is open, the connection is left alone. This lets you manage the connection's lifetime and wrap multiple method calls in a transaction.
You can also check the test scenarios
Sorry buddy. I dont understand.
Will the above code always open the connection and kept open?
Will cause any performance issues?
Yes, Insight does auto opens and closes the connections.
Thank You very much for confirming.
Cheers.