简体   繁体   English

在许多公司的asp.net mvc 3 Web应用程序上共享公用.net类库的一种容易维护的方法是什么?

[英]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: 这是我们库中的内容:

  • Base classes for controllers and services 控制器和服务的基类
  • Business objects (stores, departments, etc) 业务对象(商店,部门等)
  • Common Partial Views (Login, Error, etc) 通用局部视图(登录,错误等)
  • Base class for HttpApplication HttpApplication的基类
  • General common code (read an INI file, create a db conn, etc) 通用通用代码(读取INI文件,创建db conn等)

The one requirement that has been giving me trouble is as follows: 给我带来麻烦的一项要求如下:

  • Lives in one place on a server. 住在服务器上的一个地方。 (ie copy local = false) (即复制本地=假)

This breaks because: 这是因为:

  • The DLL containing the HttpApplication class must be in the same directory as the web apps dll to launch. 包含HttpApplication类的DLL必须与要启动的Web应用程序dll位于同一目录中。 I haven't found a way around that. 我还没有找到解决方法。 I'm ok with duplicating this code in every app, but would rather not. 我可以在每个应用程序中复制此代码,但是宁愿不要。
  • The shared views don't like to work if I use Assembly.LoadFrom() to load the dll from the shared location. 如果我使用Assembly.LoadFrom()从共享位置加载dll,则共享视图不喜欢工作。 (I've been using this method to precompile my views) (我一直在使用这种方法来预编译我的视图)
  • Any namespace shortcuts in web.config break at runtime with compilation errors because the web.config is parsed before the assembly is loaded. web.config中的任何名称空间快捷方式都会在运行时因编译错误而中断,因为在加载程序集之前已对web.config进行了解析。

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.

相关问题 为ASP.NET Core和MVC 5应用程序构建一个简单的类库 - Build a simple class library for ASP.NET Core and MVC 5 Applications 类库参考在Asp.net 5 MVC 6 Web应用程序中不起作用 - Class library reference is not working in Asp.net 5 mvc 6 web application ASP.NET Web应用程序 - Asp.net web applications 在Web应用程序和Visual Studio for ASP.NET MVC上使用图像 - Using images on Web Applications and Visual Studio for ASP.NET MVC 是否可以使用“ Windows桌面类库”模板来创建由多个ASP.NET Web应用程序使用的类库? - Can the “Windows Desktop Class Library” template be used to create a class library used by mutliple ASP.NET web applications? ASP.NET Web应用程序中的常量的一些示例或用法是什么? - What are some examples or uses of constants in ASP.NET web applications? 多对多关系ASP.NET MVC和ASP.NET WEB API - Many to many relationship ASP.NET MVC and ASP.NET WEB API 使用 Asp.Net 核心 Mvc 或 Razor Pages 构建的 Web 应用程序中是否使用了任务并行库、PLINQ 或并发集合? - Is Task parallel library, PLINQ or Concurrent Collections used in Web Applications built with Asp.Net core Mvc or Razor Pages? ASP.NET MVC4 Web API-控制返回的JSON格式,包括哪些内容? - ASP.NET MVC4 Web API - Control over formatting of returned JSON and what is included? 无法调试ASP.Net MVC应用程序 - Unable to debug ASP.Net MVC Applications
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM