[英]What is an easily maintainable way to share a common .net class library over many corporate asp.net mvc 3 web applications?
I've been struggling to do this in a way that fulfills all of my requirements. 我一直在努力满足我的所有要求。
Here is what we have in our library: 这是我们库中的内容:
The one requirement that has been giving me trouble is as follows: 给我带来麻烦的一项要求如下:
This breaks because: 这是因为:
My question to you folks is how do you handle your common code in a similar environment? 我对大家的问题是,您如何在类似的环境中处理通用代码?
The GAC seems to be more trouble than its worth, and we want all of our apps to be using the same code, and not have multiple apps on multiple versions and have to maintain all of that. GAC似乎比其价值还麻烦,我们希望所有应用程序都使用相同的代码,而不是在多个版本上具有多个应用程序,而必须维护所有这些。 Are there design patters/best practices that can guide us in this regard? 是否有设计模式/最佳实践可以在这方面指导我们?
Also, as a bonus, if you can solve any of the problems above, that would be great, too. 另外,作为奖励,如果您可以解决上述任何问题,那也很好。
Thanks! 谢谢!
Edit: I guess a question that follows is whether or not we should even have a directory with the common dll(s) on the server, or if they should only be deployed as projects are deployed/updated? 编辑:我想接下来的问题是我们是否应该在服务器上甚至有一个包含通用dll的目录,或者是否仅应在部署/更新项目时进行部署?
Firstly, you will want to separate out what you're trying to achieve. 首先,您将想要分离出您想要实现的目标。 Don't create 1 library that does everything or you will have a Big Ball of Mud . 不要创建一个可以完成所有任务的库,否则您将拥有一个大泥巴球 。 Don't be afraid to create several maintainable libraries to achieve what you're after. 不要害怕创建几个可维护的库来实现您所追求的目标。 Is there a specific reason it needs to be stored in one location? 是否有特定原因需要将其存储在一个位置?
For example, several of the items you mention are MVC or web specific. 例如,您提到的几个项目是MVC或特定于Web的。 If you have items that can be reused by MVC, create a class library that contains MVC base classes you inherit and reference them in your project. 如果您有可以被MVC重用的项目,请创建一个类库,其中包含您继承的MVC基类,并在项目中引用它们。 Use the single responsibility principle as much as possible. 尽可能使用单一责任原则。
Regarding the other items you mentioned, like database connectivity, if it's reusable, abstract it out in a data access class library and reference it. 关于您提到的其他项目,例如数据库连接性(如果可重用),请将其抽象到数据访问类库中并进行引用。 Other simple operations like reading an ini file or creating a file, create another library and abstract it to easy to use methods. 其他简单的操作,例如读取ini文件或创建文件,创建另一个库并将其抽象为易于使用的方法。
I prefer to copy the library dlls locally. 我更喜欢在本地复制库dll。 You never know when you will need to make changes to the library, but you don't want all of your projects to stop compiling. 您永远不知道何时需要对库进行更改,但是您不希望所有项目都停止编译。 When you're ready to implement a new version of the library, copy the dll in and recompile. 当您准备实现该库的新版本时,请复制dll并重新编译。
Not sure why all the hate towards the gac. 不知道为什么所有的仇恨都对联邦军。 It was designed to handle this specific problem. 它旨在解决此特定问题。 Install your common dlls to the gac and all apps can see them. 将常见的dll安装到gac,所有应用程序都可以看到它们。 Need to deploy a new one, just re-install it in one place. 需要部署一个新的,只需将其重新安装在一个地方即可。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.