<Pro ASP.NET MVC 5> - Note02

来源:互联网 发布:the weeknd earned it 编辑:程序博客网 时间:2024/06/03 19:41

CHAPTER 3: The MVC Pattern


Building Loosely Coupled Components


  1. Implement an interface that defines all of the public functions required.
  2. By introducing interface, I ensure that there is no direct dependency between the function user and its implementation.


Using Dependency Injection


Breaking and Declaring Dependencies

public class PasswordResetHelper {private IEmailSender emailSender;public PasswordResetHelper(IEmailSender emailSenderParam) {emailSender = emailSenderParam;}public void ResetPassword() {// ...call interface methods to configure e-mail details...emailSender.SendEmail();}}


Injecting Dependencies



Using a Dependency Injection Container

  1. I register the set of interfaces or abstract types that my application uses with the DI container, and specify which implementation classes should be instantiated to satisfy dependencies.
  2. The DI container puts information together, creates the MyEmailSender object and then uses it as an argument to create a PasswordResetHelper object, which I am then able to use in the application.
  3. It is important to note that I no longer create the objects in my application myself using the new keyword. Instead, I go to the DI container and request the objects I need.
  4. Ninject, you can get details at www.ninject.org.


Getting Started with Automated Testing


Understanding Unit Testing


Understanding Integration Testing

Selenium RC (http://seleniumhq.org/), which consists of a Java "server" application that can send automation commands to Internet Explorer, Firefox, Safari, or Opera, plus clients for .NET, Python, Ruby, and multiple others so that you can write test scripts in the language of your choice. Selenium is powerful and mature; its only drawback is that you have to run its Java server.



CHAPTER 6: Essential Tools for MVC


Using Ninject

The idea is to decouple the components in an MVC application, with a combination of interfaces and DI container that creates instances of objects by creating implementations of the interfaces they depend on and injecting them into the constructor.





0 0
原创粉丝点击