简体   繁体   English

为多个客户定制 c# WinForm 应用程序

[英]Customize c# WinForm application for multiple customers

Think at this scenario:想想这种情况:

I have a c# windows form application.我有一个 c# windows 表格申请。 This application was the same for all my customers.这个应用程序对我所有的客户都是一样的。 Now one of them needs to modify a form adding new textbox and new logic.现在他们中的一个需要修改一个表单,添加新的文本框和新的逻辑。

I obviously don't wanto to duplicate my application, and inserting IF statements with customer-Id to control the logic can easly drive to a spaghetti-style code.我显然不想复制我的应用程序,并且插入带有客户 ID 的 IF 语句来控制逻辑可以很容易地驱动到意大利面条式的代码。

I think that in this situation I can create a separate dll project for each customer;我认为在这种情况下,我可以为每个客户创建一个单独的 dll 项目; Inside I can write custom forms implements same interface as default form (and same for logic classes) and I can try to switch those dll via configuration file or build the project with the right customer dll (or using, for example, Windsor Castle for DI).在里面我可以编写自定义 forms 实现与默认形式相同的接口(逻辑类也相同),我可以尝试通过配置文件切换这些 dll 或与正确的客户 Z06416233FE5EC4C593312 使用 Wind 的示例,例如 Castle, )。

Is this a valid pattern?这是一个有效的模式吗? Exists a different way?存在不同的方式?

update更新

I try to list:我尝试列出:

I think in this case, MEF would be a better choice.我认为在这种情况下, MEF会是一个更好的选择。 Castle is more like a DI engine for business logic, useful for controlling the object life cycle, especially when you want to be able to switch the way the program works (multiple small threads or one single large operation in one thread). Castle 更像是一个业务逻辑的 DI 引擎,用于控制 object 生命周期,尤其是当您希望能够切换程序的工作方式时(多个小线程或一个线程中的单个大操作)。
MEF, on the other hand, strips you of the need to add a config file for this type of configuration.另一方面,MEF 使您无需为此类配置添加配置文件。 You just operate with libraries.您只需使用库进行操作。 I think MEF is best for client-side GUI forms.我认为 MEF 最适合客户端 GUI forms。

If you are developing a multitenant application, there are DI frameworks like Autofac which support this kind of customization.如果您正在开发多租户应用程序,那么有像Autofac这样的 DI 框架支持这种定制。 Take a look at this article看看这篇文章

You can also use your Source Control system to help you out.您还可以使用源代码控制系统来帮助您。 When you need to customize, create a branch and do the customization there so you do not have to duplicate your code.当您需要自定义时,创建一个分支并在那里进行自定义,这样您就不必复制代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM