访问BLL的功能在presentation层 [英] Accessing Function of BLL in Presentation layer

查看:110
本文介绍了访问BLL的功能在presentation层的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个应用程序,用户可以自己注册和注册后,他转到主页Page.I我在MVC3但它转换成3Tier.For这个我有一个名为原始项目为presentation并提出这样在DAL,并添加模型文件夹和的DbContext,以及成和删除的型号从presentation.And现在我要创建BLL,我想编写所有的逻辑插入,删除和更新,并希望访问在我的控制器这是我的presentation.How我能做到这一点?
请指导我这个!

I have created an Application where user can Register himself and after Registration he navigate to Home Page.I am doing this in MVC3 but by converting it into 3Tier.For this i have named the Original Project as Presentation and made the DAL and Added the Model Folder and DbContext as well into that and Deleted the Model From the Presentation.And now i have to create BLL where i want to write all the Logic for Insert,Delete and Update and want to access it in My Controller which is in My Presentation.How can i do this? Please Guide me on this!!!

推荐答案

好像你要求我们重写你的整体解决方案适合你?

Seems like you are asking us to rewrite your whole solution for you?

有许多入门套件网上说给你如何把事情做了提示。有许多不同的方式来实现相同的结果。我给你的我该怎么做事情的简介。

There are many starter kits online that give you a hint on how to get things done. There are many different ways to achieve the same result. I'll give you a brief outline of how I do things.

在这个例子中我会参考客户,你可以修改它以适合您的解决方案。

For this example I will make reference to customers, you can modify it to fit in with your solution.

我有一个叫解 MyProject.DomainModel 。在这个项目中,我有我的客户类:

I have a solution called MyProject.DomainModel. In this project I have my customer class:

public class Customer
{
     public int Id { get; set; }

     public string FirstName { get; set; }

     public string LastName { get; set; }

     public int Age { get; set; }
}

我有一个项目叫 MyProject.EntityFramework 。在这里,我有我的所有库类。客户资料库的方法的例子:

I have a project called MyProject.EntityFramework. Here I have all my repository classes. Example of a customer repository method:

public IEnumerable<Customer> FindAll()
{
     return DatabaseContext.Customers;
}

然后我有另一个项目叫 MyProject.Services 。一位顾客服务,会叫你的客户资料库。是不是允许需要一个服务层,但是当我需要一些逻辑或者需要调用其他存储库,然后我用一个服务层。这就是我称之为从服务层的存储库的方法:

I then have another project called MyProject.Services. A customer service would call your customer repository. A service layer isn't allows needed but when I need some logic or need to call other repositories then I use a service layer. This is how I would call a repository method from the service layer:

public interface ICustomerService
{
     IEnumerable<Customer> FindAll();
}

public class CustomerService : ICustomerService
{
     private readonly ICustomerRepository customerRepository;

     public CustomerService(ICustomerRepository customerRepository)
     {
          this.customerRepository = customerRepository;
     }

     public IEnumerable<Customer> FindAll()
     {
          return customerRepository.FindAll();
     }
}

您将看到的CustomerService构造函数接受ICustomerRepository的一个实例。这是由依赖注入框架照顾像 Autofac

You will see that the CustomerService constructor receives an instance of ICustomerRepository. This is taken care of by a dependency injection framework like Autofac.

在你的控制器,你将拥有一个具有列表视图中显示所有的客户列表的操作方法:

In your controller you will have a List action method that has a List view to display all your customers:

public class CustomerController : Controller
{
     private readonly ICustomerService customerService;

     public CustomerController(ICustomerService customerService)
     {
          this.customerService = customerService;
     }

     public ActionResult List()
     {
          IEnumerable<Customer> customers = customerService.FindAll();

          return View(customers);
     }
}

有比这更给它。你将不得不在网上下载一些入门套件,并通过它的工作,让你在正确的道路上。我给了只是一个大体的轮廓。

There is much more to it than this. You will have to download some starter kits online and work through it to get you on the right path. What I have given is just a general outline.

我希望这有助于。

这篇关于访问BLL的功能在presentation层的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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