i am working first time on the three layer architecture, I've created three Projects in one Solution, Project one is named BLL, second is named DAL and third one is names Model, I've Created interface in Model, now want to Create Business Logics in BLL and want to connect it to the DAL where I've connected my Data Base.
For this Purpose I've added Reference of each Project With other like I've Added Reference of BLL in Model and Added reference of BLL in DAL.
now for the time i've created a class is DAL in which i've Connected my DB and have alos Created a Windows Form in Model,
the class in which I've connected DB is
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient();
namespace WindowsFormsApplication3
{
class DB
{
public void fnc_ConnectoToDB(ref SqlConnection cn)
{
string strConnectionString = null;
strConnectionString = @"Data Source=AHSANMUGHAL;Initial Catalog=SurveyBuilder;User ID=sa;Password=ahsan";
cn = new SqlConnection();
cn.ConnectionString = strConnectionString;
cn.Open();
}
public void fnc_CloseCn(ref SqlConnection cn)
{
if (cn.State == ConnectionState.Open == true)
{
cn.Close();
}
}
}
}
i know this is bit confusing question but I hope you guys will understand it and will ans ASAP
first of all, you need to make your class public.
public class DB
Try to use a dependency injection framework like ninject.
Here is an example:
Your implementation:
public class Samurai {
public IWeapon Weapon { get; private set; }
public Samurai(IWeapon weapon)
{
this.Weapon = weapon;
}
}
And a module to give the Samurai it's weapon:
public class WarriorModule : NinjectModule
{
public override void Load()
{
this.Bind<IWeapon>().To<Sword>();
}
}
Simple as that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With