Asp.net,C#,.NET MVC [英] Asp.net, C#, .NET MVC

查看:90
本文介绍了Asp.net,C#,.NET MVC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你通过对象构造函数参数松散地耦合对象依赖关系来实现哪些设计模式以改进代码中的单元测试?

1-adapter

2-Dependency注塑

3-Abstract Factory

4-Observer

5-Singleton



我尝试了什么:



你实现了哪些设计模式,以便通过松散地耦合对象依赖关系来改进代码中的单元测试对象构造函数参数?

1-adapter

2-Dependency Injection

3-Abstract Factory

4-Observer

5-Singleton

which design pattern do you implement in order to improve unit testing in your code by loosely coupling object dependencies through object constructor arguments?
1-adapter
2-Dependency Injection
3-Abstract Factory
4-Observer
5-Singleton

What I have tried:

which design pattern do you implement in order to improve unit testing in your code by loosely coupling object dependencies through object constructor arguments?
1-adapter
2-Dependency Injection
3-Abstract Factory
4-Observer
5-Singleton

推荐答案

答案:依赖注入







依赖注入(DI),也称为控制反转(IoC),可以用作一种鼓励这种松散耦合的技术。实现DI有两种主要方法:构造函数注入和setter注入。显然,在某些时候,某些东西必须负责创建将被注入另一个对象的具体对象。注入器可以是父对象,我称之为DI控制器,或者可以外部化并由DI容器框架处理。
Answer:Dependency Injection



Dependency Injection (DI), also more cryptically known as "Inversion of Control" (IoC), can be used as a technique for encouraging this loose coupling. There are two primary approaches to implementing DI: constructor injection and setter injection. Obviously, at some point, something must be responsible for creating the concrete objects that will be injected into another object. The injector can be a parent object, which I'll call the "DI controller", or can be externalized and handled by a "DI container" framework.


这篇关于Asp.net,C#,.NET MVC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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