What's the best way to reference a .DLL - as a normal reference or as a web service?
What is the best way to reference an existing .NET dll (Class library)? Is there any benefit to expose web services from the class libr开发者_如何学Pythonary and reference these as opposed to referencing the actual .dll (Although one benefit of the web service approach is the granularity and thus surface area exposed is up to you at coding time)?
I am thinking with loose coupling in mind, as a criteria.
Thanks
I would have thought that referencing "normally" was generally your best bet. I'd only reference a Web Service if that was the only option.
If loose-coupling is a key driver then you're better off using Dependency Injection / IoC.
I don't believe web services are what you are looking for. Web services are not a blanket decoupling tool, and should not be used as one.
First and foremost, I would say the first thing to do before referencing an existing .NET class library is ask yourself, how much risk are you taking if you access this directly? Or, what am I going to have to do if the API/functionality of this library changes?
If you are referencing System.dll, then you know it's not going to change (.NET Framework upgrades aside) and I would recommended referencing it directly. There's no real risk here. If the referenced library is highly suspect or changes often, then you want to protect your consuming library from being dependent on it.
There are many different ways to decouple your library from the library you are consuming. As Adrian K mentions, Dependency Injection and Inversion of Control are a good place to start. They might also be overkill and a simple application of the Adapter pattern may suffice. It really depends on the situation.
精彩评论