简体   繁体   English

在 ASP.NET 中使用 COM,还是使用标准的 DLL?

[英]Using COM in ASP.NET, or use a standard DLL instead?

We are moving a classic ASP application with VB6 COM objects, over to the .NET world, and we are puzzled about how to migrate our COM objects in as straightforward a manner as possible. We are moving a classic ASP application with VB6 COM objects, over to the .NET world, and we are puzzled about how to migrate our COM objects in as straightforward a manner as possible. I have found a lot of 'how-to' articles, but not much in the way of 'why' articles.我找到了很多“操作方法”文章,但没有多少“为什么”文章的方式。 Are we better off rebuilding the COM objects as standard DLLs which query the database (this is a DB-heavy application), or should we rebuild them as new COM objects in C#?我们最好将 COM 对象重建为查询数据库的标准 DLL(这是一个 DB 密集型应用程序),还是应该将它们重建为 ZD7EFA19FBE7D3972FD5ADB6024223D7 中的新 COM 对象? What are the advantages and disadvantages of each approach?每种方法的优点和缺点是什么? Is there yet a different approach we should consider?我们还应该考虑另一种方法吗? We are not yet a very strong shop in .NET so any and all suggestions are most welcome.我们在 .NET 还不是一家非常强大的商店,因此欢迎提出任何建议。

thanks in advance, Mike提前谢谢,迈克

This is a hard question, as there are a lot of variables.这是一个很难的问题,因为有很多变数。 Let's assume, for this thread, that you have a decent amount of separation of concerns and a set of COM DLLs with decent performance.让我们假设,对于这个线程,您有相当数量的关注点分离和一组具有良好性能的 COM DLL。

Assuming the above and taking your post into account (tons of code in the COM components), the path i would normally look at is rewriting the UI in .NET first and use .NET wrappers to call the COM components. Assuming the above and taking your post into account (tons of code in the COM components), the path i would normally look at is rewriting the UI in .NET first and use .NET wrappers to call the COM components. This is easily done by referencing the COM component.这可以通过引用 COM 组件轻松完成。 Moving to some native DLL method might help if you have a performance problem once wrapped, but it is a more complex direction to set up the code to invoke native methods, so I would not head that route first.如果您在打包后遇到性能问题,则迁移到某些本机 DLL 方法可能会有所帮助,但设置代码以调用本机方法是一个更复杂的方向,因此我不会先走这条路。

You then have two directions to possibly head.然后,您可能有两个方向。 Focus on user stories (usability) or focus on migrating individual libraries (COM DLL >> assembly one at a time).专注于用户故事(可用性)或专注于迁移单个库(COM DLL >> 一次组装一个)。 I prefer the story direction, althought you will potentially end up with dead code.我更喜欢故事的方向,尽管你最终可能会得到死代码。 Rather than think about migrating, I would rewrite one story at a time, so you are focused on doing it right in .NET.我不会考虑迁移,而是一次重写一个故事,因此您专注于在 .NET 中正确执行此操作。 Migration ends up with a lot of COM code written in .NET, which is nasty.迁移最终会产生大量用 .NET 编写的 COM 代码,这很讨厌。

I would consider finding at least one .NET expert, whether hired as an employee or a consultant, so you do not let old habits leak in bad code.我会考虑至少找一位 .NET 专家,无论是作为员工还是顾问,这样你就不会让旧习惯泄漏到糟糕的代码中。 This expert should be hired primarily to keep you on the right road and not as another set of coding hands.聘请该专家主要是为了让您走在正确的道路上,而不是作为另一组编码人员。 Not saying the person cannot code, but make sure you do not over utilize this person as a warm body, as his primary job, during development, is to keep you from shooting yourself in the foot.不是说这个人不会编码,而是确保你不要过度利用这个人作为一个温暖的身体,因为他的主要工作,在开发过程中,是让你不要在自己的脚上开枪。 If you can get this person in early, consider hiring someone with some architecture experience to help design the application for .NET.如果您能尽早找到此人,请考虑聘请具有一定架构经验的人来帮助设计 .NET 的应用程序。 It is more expensive to experiment up front than it is to refactor later.前期试验比后期重构成本更高。

DON'T try migration programs.不要尝试迁移计划。 They DON'T work.他们不工作。 You are not only making a development platform shift, you are making a complete paradigm shift.您不仅在进行开发平台的转变,而且还在进行彻底的范式转变。 If you try to use any automated tool to migrate code, you will end up with an inferior application.如果您尝试使用任何自动化工具来迁移代码,您最终会得到一个劣质的应用程序。

One other thing.另一件事。 If you are a VB shop, consider moving to C#.如果您是 VB 商店,请考虑转移到 C#。 It sounds counter productive, as there is a learning curve, but sticking with VB means you will try to write VB6 in VB.NET.这听起来适得其反,因为存在学习曲线,但坚持使用 VB 意味着您将尝试在 VB.NET 中编写 VB6。 The end result is a bad code base that is hard to refactor.最终结果是糟糕的代码库难以重构。

My experience would suggest you should re-write the COM objects into a DLL because the risk is low that something will break during conversion and the time this will take is a LOT shorter than re-writing in C#.我的经验建议您应该将 COM 对象重新写入 DLL,因为在转换过程中发生故障的风险很低,而且所花费的时间比在 ZD7EFA19FBE7D3972FD5ADB602422 中重新写入要短很多。

Migrating to .NET can only really be done by hand, but once in a COM DLL you can do this on a part by part basis.迁移到 .NET 只能手动完成,但是一旦在 COM DLL 中,您可以逐个完成此操作。

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

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