While I know there are many ways of doing this, I'm just wondering if this is way off base.
I have a solution that has three DLL's, UI (asp.net web application), Business layer, and DAL. So my code mainly looks like this (very raw example code):
UI
protected void Page_Load(object sender, EventArgs e)
{
Beanpole.Business.Project myProject = new Beanpole.Business.Project();
myProject.LoadProject(Convert.ToInt32(Request["id"].ToString()));
Response.Write(myProject.ProjectName + "<br>" + myProject.ProjectDescription);
}
BLL
using ...
using Business.Providers;
namespace Business
{
public class Project
{
public string ProjectName { get; set; }
public string ProjectDescription { get; set; }
public bool LoadProject(int projectId)
{
DataTable dt = DBProvider.Instance().LoadProject(projectId).Tables[0];
if (dt.Rows.Count == 0)
return false;
LoadProjectFromRow(dt.Rows[0]);
return true;
}
internal void LoadProjectFromRow(DataRow row)
{
this.ProjectName = (string)row["Name"];
this.ProjectDescription = (string)row["Description"];
}
}
}
Data provider (Business dll)
namespace Business.Providers
{
public class DBProvider
{
private static IDataAccess _getDataAccessComponent = null;
public static IDataAccess Instance()
{
if (_getDataAccessComponent == null)
{
const string className = "My.Data.DataAccess, My.Data";
_getDataAccessComponent = (IDataAccess)Activator.CreateInstance(Type.GetType(className));
}
return _getDataAccessComponent;
}
}
}
DAL Interface
namespace My.Data
{
public interface IDataAccess
{
DataSet LoadProject(int projectId);
}
}
Data access
namespace My.Data
{
public class DataAccess : IDataAccess
{
public DataSet LoadProject(int projectId)
{
SqlParameter[] _params = new SqlParameter[1];
_params[0] = new SqlParameter("@ProjectId", SqlDbType.Int) { Value = projectId };
return SqlHelper.ExecuteDataset(connString, "up_LoadProject", _params);
}
}
}
The main issue I have with this set up is the DBProvider
class. It bothers me for some reason and I just can't seem to figure out why, or shake it and keep going. It's almost like it's causing my writers block. I have this same pattern working very well in another application and all is good, but it seems like a lot of extra code for no gain.
Any tips would be helpful.
Also I'm working on 3.5 right now, but thinking of moving to 4.0 once I can get VS 2010.
Edit: Just picked up VS 2010 over the weekend, so I'm moving the app over to 4.0 in hopes of better EF or LINQ to SQL support.