我应该如何定位插入组件组件

2023-09-07 01:02:39 作者:直到最后⒈句

我们都将动态地从单独的DLL加载某些组件的应用程序。这些组件具有一个固定的名称,但我们想本地化名称被显示给用户等的名称需要进行本地化。

We have an application which will dynamically load some components from separate dlls. These components have a fixed name but we want localised names to be displayed to the user and so the names need to be localised.

这名需要本地化的事实并不是组件本身的关注,所以我们真的不希望污染与像显示名称或LocalisedName属性组件的模型,有资源的组件住在DLL中的组件。但是,因为这些组件是可插拔的,我们不能有资源的显示名住在应用程序,那么当我们添加新的组件,需要应用程序的资源进行更新,击败使得组件可插入点。

The fact that the name needs to be localised is not a concern of the component itself, so we don't really want to pollute the model of the component with a property like DisplayName or LocalisedName, and have the resources for the component live in the dll for the component. But as these components are pluggable we can't have the the resource for the display name live in the application, as then when we added new components, the resources for the application would need to be updated, defeating the point of making the components pluggable.

时有共同的解决这个问题?我们可以看到的可能的解决方案是:

Is there are common solution to this issue? The possible solutions we could see were:

1 \有它的GUI code来电显示的名字一个叫属性的显示名称。此工程确定,与存在于相同的dll作为(或卫星的DLL),它包含该组件的组件的资源。但是,这似乎污染模型信息,该组件不应该在意。

1\ Have a property called display name which the gui code calls to display the names. This works ok, with the resources existing in the same dll as (or satellite dlls of) the assembly that contains the component. But this seems to pollute the model with information that the component should not care about.

2 \有无与GUI应用程序查找资源用于从它自己的资源文件命名组件。这将失败,因为该应用程序时,需要添加含有新的动态加载组件新的组装有资源更新。

2\ Have the app with the GUI look up the resources for the named component from its own resource files. This fails because the app needs to have its resources updated when new assemblies containing new dynamically loaded components are added.

3 \拥有应用程序的外观在组件来自该组件的本地化名称的程序集的资源。这似乎好作为本地化名称为如此分布与它的组件的组件的存在,但与presentation层该应用指使由组分的dll本地化字符串的查找,所以该组件不需要知道任何关于本地化,因此它的型号是不被污染。

3\ Have the app look in the resources of the assembly the component came from for the localised name of the component. This seems good as the localised name exists in the assembly for the component so is distributed with it, but the app with the presentation layer instigates the lookup of the localised string from the components dll, so the component does not need to know anything about the localisation and so its model is not polluted.

是选项3可能吗?有没有我们没有考虑一些其他的选择吗?

Is option 3 possible? Is there some other option we have not considered?

欢呼声......

推荐答案

选项3是我会做什么,我认为这是可能的。如果您知道插件的名称,可以使用反射实例化一个类。那么您查询类的LocalizedName,该插件将获取从资源程序集。我presume您了解如何卫星资源集的工作。

Option 3 is what I would do, and I think it's possible. If you know the name of the plugin and can instantiate a class using reflection. You then query that class for a LocalizedName, which the plugin would fetch from its resource assembly. I presume you understand how satellite resource assemblies work.

有没有具体的关于#3,不适合你的东西?如果你指定什么不,我也许可以帮助...

Is there something specific about #3 that does not work for you? If you specify what doesn't I might be able to help...