创建一个借口类IDAL:不需要方法体的方法。将class装换成interface
MVC:web.config <add key="CDAL" value="DAL"/>API的web.config <add key="CDAL" value="DAL"/>添加到<appSettings>创建一个接口 没有方法体的方法
namespace IDAL
{ using MODEL; public interface IdalUser { int UsertAdd(Usert user); int Login(string name,string pass); }}namespace IDAL
{ using MODEL; public interface IImagedal { int ImagesAdd(ImageModel img);/// <summary>
/// 获取所有的信息 /// </summary> /// <returns></returns> List<ImageModel> GetImage(); }}建立一个工厂类:
namespace GongChang
{ using System.Configuration; using System.Reflection; using IDAL; public class gongchang { private static readonly string kname = ConfigurationManager.AppSettings["CDAL"]; public IdalUser CreateuserDAL() { return (IdalUser)Assembly.Load(kname).CreateInstance(kname + ".UsertDal"); } public IImagedal CreateimgDAL() { return (IImagedal)Assembly.Load(kname).CreateInstance(kname + ".ImageDal"); } }}BLL实例化:
using MODEL;
using DAL; using GongChang; using IDAL;gongchang gc = new gongchang();
IImagedal bll = null; public ImagesBll() { if (bll == null) { bll = gc.CreateimgDAL(); } } //ImageDal bll = new ImageDal();MVC api 记者引用接口