在插件架构的反思与属性 [英] Reflection vs. Attributes in plugin architecture

查看:114
本文介绍了在插件架构的反思与属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作加载插件在启动时从一个子目录的应用程序,目前我使用反射来遍历每个组件的类型,并寻找公共类实现IPluginModule接口这样做。

I am working on an application that loads plugins at startup from a subdirectory, and currently i am doing this by using reflection to iterate over the types of each assembly and to find public classes implementing the IPluginModule interface.

由于反射涉及到的性能损失,而且我预计会有几个插件一段时间后,我想知道,如果这将是确定应用在组件级别的自定义属性很有用,这可能会遍历类型前应检查(在装配可能大概有十几类,其中包括1实施者IPluginModule的)。

Since Reflection involves a performance hit, and i expect that there will be several plugins after a while, i wondered if it would be useful to define a custom attribute applied at the assembly level, that could be checked before iterating over the types (possibly about a dozen types in an assembly, including 1 implementor of IPluginModule).

属性,如果present,便可以提供一种方法来恢复所需要的类型或实例,并遍历类型然后将只能是回退机制。存储类型的信息在一个配置文件是不是一种选择。

The attribute, if present, could then provide a method to return the needed types or instances, and iterating over the types would then only be a fallback mechanism. Storing the type info in a configuration file is not an option.

这会提高性能,还是只是无关紧要相比的时候,其实需要从存储加载程序集?此外,将这种用法是适合所有的属性?

Would this improve performance, or does it just not matter compared to the time to actually takes to load the assembly from storage? Also, would this usage be appropriate for an attribute at all?

推荐答案

我会回答你的问题有一个问题:为什么你担心这个

I will answer your question with a question: Why are you worried about this?

您正在担心一个的的潜力的性能在的一次命中的操作,因为那里的也许的是几个插件在稍后的日期。

You're worrying about a potential performance hit in a one time operation because there might be several plugins at a later date.

除非你的应用程序的启动时间过长给用户,我不会浪费时间考虑这个问题 - 有可能是更好的东西,你可以工作,以提高应用程序

Unless your application startup time is excessively long to a user, I wouldn't waste time thinking about it - there are probably much better things that you can work on to improve your application.

这篇关于在插件架构的反思与属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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