I'm working on an ASP.NET project using VB.NET that uses Dapper and the code as implemented so far runs fine with just me testing. In the example below, Dapper calls a stored proc.
But my I am wondering primarily right now if the method of generating an open connection (see dbConnFactory below) implemented in the Domain project is not good practice.
AutomoblieDomain project
Imports System.Data.Common
Imports Dapper
Namespace DAL
Public Class DomainSettings
Public Shared Property CustomConnectionString As String
End Class
Public Class dbConnFactory
Public Shared Function GetOpenConnection() As DbConnection
Dim connection = New SqlClient.SqlConnection(CustomConnectionString)
connection.Open()
Return connection
End Function
End Class
Public Class CarTypes
Public Property CarTypeID As Integer
Public Property CarTypeText As String
Public Shared Function GetList() As IEnumerable(Of CarTypes)
Using conn = dbConnFactory.GetOpenConnection()
Dim _list = conn.Query(Of CarTypes)("dbo.CarTypes_GetList", CommandType.StoredProcedure).ToList()
Return _list
End Using
End Function
End Class
End Namespace
Web UI Project
Imports System.Net
Imports System.Web.Http
Imports AutomobileDomain
Public Class CarTypesController
Inherits ApiController
<HttpGet()>
Public Function GetList() As IEnumerable(Of DAL.CarTypes)
Return DAL.CarTypes.GetList()
End Function
End Class
** UPDATE ** 4/1/2013
Also, can there be pitfalls to calling a Shared
function from .NET's Web Api, whether it the function is for Get, Put, Post, or Delete?