与我的示例案例一样,通常将Unity Application Block或DI与Entity Framework一起使用有什么好处
|
在下面的伪代码中,我分为3层:用于ASP.NET WebForms应用程序的UI,BL和DL。
有人可以给我一些关于为什么我需要使用依赖注入的建议吗
和团结在这里?我使用了很多接口(主要用于邮件或文件解析器之类的第三方组件,因此我可以根据需要替换它们而无需更改其他层),但是我不明白为什么我应该在EF EntityObjects上使用接口。我似乎无法在网络上找到一个示例,该示例将显示出超出理论上不真实案例的实际优势。
namespace Sample.ASP.NET.UI
{
using Sample.ASP.NET.BusinessLayer;
using Sample.ASP.NET.DataModel;
protected class AspxCodeFile
{
protected Page_Load()
{
GridView.DataSource=BusinesLayer.Products.GetProductsAsList();
}
}
}
namespace Sample.ASP.NET.BusinessLayer
{
using Sample.ASP.NET.DataModel;
protected class Products
{
public static List<Product> GetProductsAsList()
{
EdmxEntities DB=new EdmxEntities();
return DB.Products.ToList<Product>();
}
}
}
namespace Sample.ASP.NET.DataLayer
{
// wrapper namespace for Entity Framework designer
// generated code off SQL Server 2008 database
// where one of the tables is called Products
// and designer created Product EntityObject
// this Product entity is referenced in both
// UI and BL.
}
没有找到相关结果
已邀请:
2 个回复
殿虫
嘘伪