MEF是微软版本的Lua吗?
我发现 MEF 和 Lua 之间有相似之处。 两者都允许您根据需要注册方法和部署。 MEF 和 Lua 都是 IoC/依赖注入的形式吗?
I see parallels between MEF and Lua. Both allow you to register methods and deploy as you need. Are both MEF and Lua forms of IoC / Dependency Injection?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我假设您意识到这些技术之间的巨大差异并关注以下问题:
此外,我假设您正在谈论嵌入式 Lua 与 Lua 作为一种语言。
首先,让我们将依赖注入与控制反转分开。 Fowler 将依赖注入定义为 IoC 的一种特定形式,因为 IoC 的思想已经变得如此普遍,以至于它不再是系统的一个显着特征。他的定义包括三种主要类型依赖注入:构造函数注入、Setter 注入和接口注入 在这三种类型中,其想法是将类或接口的特定实现注入到需要它的类或方法中,因为它允许您将依赖项和使用它的类解耦。只要它们遵循契约,您就可以编辑和交换依赖项的实现,而无需其使用者关心或受到影响。
使用此定义,我会说 MEF 通过,而嵌入式 Lua 失败。 MEF 主要是一个依赖注入框架。 它允许您动态加载和组合实现特定契约的外部类。 另一方面,Lua 允许通过脚本进行扩展,但几乎没有契约的方式。 当然,您可以为您的应用程序提供一个 Lua API,这就是某种合同,但它无法确保遵守真正的合同。
IoC 更广泛。(Fowler,维基百科)共同的主题是主程序流暂时放弃控制,但从正在执行工作的组件接收流状态更新。 实现此目的的常见方法包括:事件、闭包和延续。
使用这个定义,MEF 可以轻松传递(控制在运行时传递给未知组件),并且您也可以为嵌入式 Lua 提供参数。 主程序一直运行,直到需要外部脚本中定义的函数为止。 此时,控制权将传递给脚本,直到完成或被中断。
需要注意的一点是 Lua 在这方面并不是特别特别。 您可以嵌入 Perl、Python、Tcl 和 Ruby。 事实上,IoC 的一般定义在现代编程环境中并不是特别有用。 这太常见了。 福勒说,这就是他引入依赖注入作为特殊情况的原因。 在 GUI、事件、线程、守护进程、闭包、延续和 monad 的世界中,一切都使用 IoC。 如今,当人们说“IoC”时,他们通常指的是某种依赖注入。
I'll assume you're aware of the huge differences between these technologies and focus on the question:
Also, I'll assume you're talking about embedded Lua versus Lua as a language.
First, let's separate Dependency Injection from Inversion of Control. Fowler defined Dependency Injection as a specific form of IoC because the idea of IoC had become so common that it was no longer a distinguishing characteristic of a system. His definition includes three main types of Dependency Injection: Constructor injection, Setter injection, and Interface injection. In all three types, the idea is to inject a specific implementation of a class or interface into a class or method that needs it. This is pretty slick because it allows you to decouple the dependency and the class that uses it. As long as they follow a contract, you can edit and swap implementations of the dependency without its consumers caring or being effected.
Using this definition, I'd say MEF passes and embedded Lua fails. MEF is largely a dependency injection framework. It allows you to dynamically load and compose external classes that implement specific contracts. Lua, on the other hand, allows extension through scripting but there is very little in the way of a contract. Sure, you could provide a Lua API for your app and that's a contract of sorts, but it does nothing to ensure a true contract is honored.
IoC is broader.(Fowler,Wikipedia) The common theme is that main program flow gives up control temporarily but receives flow status updates from components that are doing the work. Common ways to accomplish this include: events, closures, and continuations.
Using this definition, MEF easily passes (control is passed to unknown components at runtime) and you can make an argument for embedded Lua as well. The main program cruises along until it needs a function defined in external script. At that point, control is delivered to the script until it's done or is interrupted.
One thing to note is that Lua isn't particularly special in this regard. You can embed Perl, Python, Tcl, and Ruby. In fact, the general definition of IoC isn't particularly useful in a modern programming environment. It's too common. Fowler says that's why he introduced Dependency Injection as a special case. In a world of GUIs, events, threads, daemons, closures, continuations, and monads, everything uses IoC. Today, when people say 'IoC', they often mean some sort of Dependency Injection.
MEF 与 Lua 无关,也与 Lua 完全不同。
MEF 是一个扩展框架(基本上是一个很棒的插件框架)。
Lua 是一种非常酷的脚本语言。
“两者都允许您注册方法并根据需要进行部署。” 这句话适用于 C、C++、C#、VB、SQL、DI 框架、JavaScript、通用汽车、福特、医院...
MEF has nothing to do with Lua, and is nothing like Lua.
MEF is a framework for extending (basically, an awesome plugin framework).
Lua is a very cool scripting language.
"Both allow you to register methods and deploy as you need." That sentence applies to C, C++, C#, VB, SQL, DI Frameworks, JavaScript, General Motors, Ford, Hospitals...