mvc中的存储库模式 [英] repository pattern in mvc

查看:73
本文介绍了mvc中的存储库模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿大家

i我只是一个初学者,我今天正在学习存储库模式,而且我在这一行代码中都有所涉及,我无法理解这行代码

neways我的问题是

Hey everyone
i am just a beginner,i was learning repository patterns today and i cam across this line of code,and i am not able to understand this line of code
neways my question is

public class HomeController : Controller
{
//
// GET: /Home/
IRepository i1;
public HomeController()
{
i1 = new Repository();
}
public ActionResult Index()
{
return View();
}



i我正在使用存储库模式,irepository是接口,存储库是实现接口的类!

但是我我无法理解下面写的这段代码


i am using a repository pattern, irepository is the interface and repository is the class that implements the interface!
but i am not able to undestand this piece of code written below

i1=new repository();



你能解释一下这个LOC的目的吗?


can you please explain what this LOC is intended to do??

推荐答案

存储库和工作单元模式:
The Repository and Unit of Work Patterns:

存储库和工作单元模式旨在在数据访问层和应用程序的业务逻辑层之间创建抽象层。实现这些模式有助于将应用程序与数据存储中的更改隔离开来,并可以促进自动化单元测试或测试驱动开发(TDD)。

The repository and unit of work patterns are intended to create an abstraction layer between the data access layer and the business logic layer of an application. Implementing these patterns can help insulate your application from changes in the data store and can facilitate automated unit testing or test-driven development (TDD).




public HomeController()
{
i1 = new Repository();
}





说明:它只是实例化 Repository类的对象。 之后,您可以使用它来调用在Repository类中实现的CRUD操作。



就像这样:



Explanation: It just instantiates an object of your Repository class.After that you can use that to call your CRUD operations which are implemented in your Repository class.

It's like this :

var students = from s in i1.GetStudents()
                       select s;





请阅读本文了解更多信息:在ASP.NET MVC应用程序中实现存储库和工作单元模式


这篇关于mvc中的存储库模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆