What is the advantages and disadvantages of using services over components?

后端 未结 3 593
悲&欢浪女
悲&欢浪女 2020-12-24 09:17

From past few months I am working on projects in latest dot net frameworks.

I feel that in latest dot net versions \"services\" are encouraged over components. Is

3条回答
  •  生来不讨喜
    2020-12-24 10:04

    It's really all to do with a Service Oriented Architecture - something that's been common for a while and is very popular.

    The idea is that distinct operations are decoupled from each other so they can be reused and modified without recompiling the apps that use it. Rather than a piece of code in a DLL being modified and copied everywhere, a service can be deployed that represents a single point of access for a particular piece of processing or source of information.

    Say you had a credit card validation component. You may write this code and compile it into a DLL and start including that in all your applications. Nothing wrong with that unless you notice a bug or the rules for CC validation change. Or maybe you want to upgrade it to check it against a blacklist. You can't do any of those things without recompiling the apps that use it.

    If your credit card validation is exposed as a service however, you can make the changes and deploy to one location. Provided the signature is the same (same parameters and response), the applications don't even have to know it's changed.

    Another advantage of using services over components is that the services can be hosted anywhere. They can be on the local server or on the other side of the world.

    Having said this, like everything you should decide the architecture on a case-by-case basis. While the credit-card validation was a good example of when a service is useful, providing a service to render HTML controls doesn't make much sense.

提交回复
热议问题