It depends on what data access technology you are using.
If you are using NHibernate, I would strongly recommend Repository-pattern along with some dependency Injection.
If you are using Linq-to-sql, you should be using Active Data Record-pattern. In this case you may or may not use dependency injection.
In case of Entity Framework, Unit-of-work-pattern can be used.
Generally I arrange my VS2005/2008 - solution like this:
And, I arrange my codes like this:
namespace MySolution.Entity
{
public interface IMyInterface
{
int Save(MyClass obj);
}
}
namespace MySolution.Entity
{
public class MyClass
{
IMyInterface _myDa;
public MyClass(IMyInterface myDa)
{
_myDa = myDa;
}
private string _message;
public string Message
{
get { return _message; }
set { _message = value; }
}
public int Save()
{
return _myDa.Save(this);
}
}
}
using MySolution.Entity;
namespace MySolution.Service
{
public class MyClassService : IMyInterface
{
public int Save(MyClass obj)
{
Console.WriteLine(obj.Message);
return 1;
}
}
}
using MySolution.Entity;
using MySolution.Service;
namespace MySolution.UI
{
class Program
{
static void Main(string[] args)
{
MyClass myobj = new MyClass(new MyClassService());
myobj.Message = "Goodbye Circular Dependency!";
myobj.Save();
Console.ReadLine();
}
}
}
You can put IMyInterface.cs
in a separate project named MySolution.Contracs
. And, then add a reference of it to the respective assembly.
Please note that, this is called layered-design, not tiered-design.
You can also employ a simple framework for your business-entities like the one used in this example.
And finally employ MVC pattern in your Winforms UI layer. You can get the example here.
And I am not providing any link for ASP.NET MVC, coz there are numerous in the net.