I am creating a Console App in C# using VS2010. It is based in 3-Layer Architecture containing three layers
- PMS.UI
- PMS.DAL
- PMS.BL
To remove Circular Dependency between PMS.DAL and PMS.BL I added an extra layer PMS.Service.
- I created a
Vehicle
class in PMS.BL which implements interfaceIVehicle
from PMS.Service. - I added reference of PMS.Service in both DAL and BL.
- Now UI calls
AddNewVehicle()
method ofVehicle
class of BL which implementsIVehicle
- BL calls
AddNewVehicle(IVehicle obj)
method of VehicleDao in PMS.DAL...
All working fine but at time of build Compiler says to add reference of PMS.Service in PMS.UI.
PMS.UI doesn't implement any interface of PMS.Service but calls AddNewVehicle()
method of Vehicle class of PMS.BL which implements IVehicle
.
Is it necessary to add reference of PMS.Service to PMS.UI only if it creates instance of Vehicle
Class of PMS.BL which implements IVehicle
present in PMS.Service..
Please help me I am new to use Interface in c#...
Thankyou Guys for your answers but i am still confused. I will present my code here.I have added all four layers as different c sharp class library(different layers).
1)PMS.UI(Added reference of PMS.BL)
Program.cs
using System;
using PMS.BL;
namespace PMS.APP
{
class Program
{
static void Main()
{
var vBo = new VehicleBo();//Compiler Says Add reference of PMS.Service here.Why is it necessary to add Reference of it??
vbo.VehicleNumber = "BA1PA 1212";
vbo.VehicleType = "Bike";
vbo.SaveNewVehicle();
}
}
}
2)PMS.BL(Added reference of PMS.DAL and PMS.Service)
VehicleBO.cs
using PMS.DAL;
using PMS.Service;
namespace PMS.BL
{
public class VehicleBo : IVehicle
{
public string VehicleNumber { get; set; }
public string VehicleType { get; set; }
public void SaveNewVehicle()
{
var vDao = new VehicleDao();
vDao.SaveNewVehicle(this);
}
}
}
3)PMS.DAL(Added reference of PMS.Service)
using PMS.Service;
namespace PMS.DAL
{
public class VehicleDao
{
public void SaveNewVehicle(IVehicle obj)
{
//code to insert in database
}
}
}
4)PMS.Service
IVehicle.cs
namespace PMS.Service
{
public interface IVehicle
{
string VehicleNumber { get; set; }
string VehicleType { get; set; }
void SaveNewVehicle();
}
}