要包含在实用程序库中的内容

时间:2022-10-20 16:20:39

With more and more projects under my belt I find that I am often repeating many common tasks from project to project, client to client. So I have started to assemble a "utility" library, a collection of these common elements that are often repeated from project to project.

随着越来越多的项目,我发现我经常重复从项目到项目,从客户到客户的许多常见任务。所以我开始组装一个“实用程序”库,这些库是这些常见元素的集合,通常在项目之间重复。

So far I have utilities to resize images, export data grids to excel, send e-mails, and replace tokenized messages.

到目前为止,我有实用程序来调整图像大小,导出数据网格excel,发送电子邮件,并替换标记化的消息。

If you were building/using a .NET utility class library, what types of processes would you see as helpful? What namespaces/groups would you envision?

如果您正在构建/使用.NET实用程序类库,那么您认为哪些类型的进程有用?你会想到什么命名空间/组?

Update

I am talking about an actual class library, separated into namespaces to group common elements.

我在谈论一个实际的类库,它被分成命名空间以组合公共元素。

5 个解决方案

#1


  1. I wouldn't write a library called 'Common' or 'Utilities' or 'Misc' or... You get the idea. Instead, I'd have a directory called 'Lib', and have each area of functionality in a separate library under that. For example, I might have Lib/Trace, Lib/UI, Lib/Net, Lib/Web for a C++ project. For C#, I'd have Lib/Acme.Trace, Lib/Acme.Windows.Forms, Lib/Acme.Net, etc. (assuming your top-level namespace/company is called 'Acme').
  2. 我不会写一个名为'Common'或'Utilities'或'Misc'的库或......你明白了。相反,我有一个名为'Lib'的目录,并在其下的一个单独的库中具有每个功能区域。例如,我可能有一个C ++项目的Lib / Trace,Lib / UI,Lib / Net,Lib / Web。对于C#,我有Lib / Acme.Trace,Lib / Acme.Windows.Forms,Lib / Acme.Net等(假设您的*命名空间/公司被称为'Acme')。

  3. YAGNI. Don't go writing code that you might need.
  4. YAGNI。不要编写您可能需要的代码。

  5. Don't throw things into a shared library until you've used them in two or more projects.
  6. 在两个或多个项目中使用它们之前,不要将内容放入共享库中。

#2


Personally, I would put some of this functionality into separate libraries, as "utility" is a rather subjective term, what one person finds helpful is not so helpful to another.

就个人而言,我会将这些功能放入单独的库中,因为“效用”是一个相当主观的术语,一个人发现有用的东西对另一个人没那么有用。

If within the library it was broken up into descriptive namespaces, then I would say that's better (e.g. resize images would be in some sort of .Drawing namespace, or in a .Drawing.dll).

如果在库中它被分解为描述性命名空间,那么我会说这更好(例如调整大小图像将在某种.Drawing命名空间中,或在.Drawing.dll中)。

#3


I have plenty of things in my class library which I share between projects:

我的课程库里有很多东西,我在项目之间分享:

  • IoC container and dependency injection framework
  • IoC容器和依赖注入框架

  • A full controller/observer framework, allows me to separate UI code from backlogic code
  • 完整的控制器/观察者框架允许我将UI代码与backlogic代码分开

  • A reasonable database-independent set of classes for executing SQL, takes care of some of the syntax differences, mainly function names
  • 用于执行SQL的合理的数据库无关的类集合负责一些语法差异,主要是函数名称

  • Lots of other helper classes and utility methods for dealing with data
  • 许多其他帮助程序类和实用程序方法来处理数据

  • Some standardized internal storage classes, like Tuple<..> etc.
  • 一些标准化的内部存储类,如Tuple <..>等。

  • Some custom collections, like Set<T>, Heap<T>, as well as plenty of utility methods for dealing with various types of collections
  • 一些自定义集合,如Set ,Heap ,以及用于处理各种类型集合的大量实用方法

The class library is added to when I need more stuff.

当我需要更多东西时,会添加类库。

#4


I'd suggest that instead of a "utility" library just make domain specific (graphics, authentication, validation, etc) libraries and only include them where they are needed. The key of course is decided how specific to be. More specificity is generally better.

我建议不要使用“实用程序”库来制作特定于域(图形,身份验证,验证等)的库,而只将它们包含在需要的地方。关键当然是决定具体是什么。更具特异性通常更好。

Irregardless if it has no domain then you probably don't understand it fully meaning that you should re-evaluate what you are doing and trying to accomplish first.

无论如果它没有域,那么你可能完全不理解它意味着你应该重新评估你正在做什么并试图先完成。

Also, remember that what is useful in one or two projects may end up only being useful in one or two projects. Adding more classes than necessary only causes maintenance issues down the road.

另外,请记住,在一个或两个项目中有用的东西最终只能用于一个或两个项目。添加超过必要的类只会导致维护问题。

#5


Though I am just a fledgling developer myself I have found RegEx functions and SQL filters to be quite useful. I also have Merge Replication functionality for MSSQL that has been quite handy for me so far.

虽然我自己只是一个初出茅庐的开发人员,但我发现RegEx函数和SQL过滤器非常有用。我也有MSSQL的合并复制功能,这对我来说非常方便。

#1


  1. I wouldn't write a library called 'Common' or 'Utilities' or 'Misc' or... You get the idea. Instead, I'd have a directory called 'Lib', and have each area of functionality in a separate library under that. For example, I might have Lib/Trace, Lib/UI, Lib/Net, Lib/Web for a C++ project. For C#, I'd have Lib/Acme.Trace, Lib/Acme.Windows.Forms, Lib/Acme.Net, etc. (assuming your top-level namespace/company is called 'Acme').
  2. 我不会写一个名为'Common'或'Utilities'或'Misc'的库或......你明白了。相反,我有一个名为'Lib'的目录,并在其下的一个单独的库中具有每个功能区域。例如,我可能有一个C ++项目的Lib / Trace,Lib / UI,Lib / Net,Lib / Web。对于C#,我有Lib / Acme.Trace,Lib / Acme.Windows.Forms,Lib / Acme.Net等(假设您的*命名空间/公司被称为'Acme')。

  3. YAGNI. Don't go writing code that you might need.
  4. YAGNI。不要编写您可能需要的代码。

  5. Don't throw things into a shared library until you've used them in two or more projects.
  6. 在两个或多个项目中使用它们之前,不要将内容放入共享库中。

#2


Personally, I would put some of this functionality into separate libraries, as "utility" is a rather subjective term, what one person finds helpful is not so helpful to another.

就个人而言,我会将这些功能放入单独的库中,因为“效用”是一个相当主观的术语,一个人发现有用的东西对另一个人没那么有用。

If within the library it was broken up into descriptive namespaces, then I would say that's better (e.g. resize images would be in some sort of .Drawing namespace, or in a .Drawing.dll).

如果在库中它被分解为描述性命名空间,那么我会说这更好(例如调整大小图像将在某种.Drawing命名空间中,或在.Drawing.dll中)。

#3


I have plenty of things in my class library which I share between projects:

我的课程库里有很多东西,我在项目之间分享:

  • IoC container and dependency injection framework
  • IoC容器和依赖注入框架

  • A full controller/observer framework, allows me to separate UI code from backlogic code
  • 完整的控制器/观察者框架允许我将UI代码与backlogic代码分开

  • A reasonable database-independent set of classes for executing SQL, takes care of some of the syntax differences, mainly function names
  • 用于执行SQL的合理的数据库无关的类集合负责一些语法差异,主要是函数名称

  • Lots of other helper classes and utility methods for dealing with data
  • 许多其他帮助程序类和实用程序方法来处理数据

  • Some standardized internal storage classes, like Tuple<..> etc.
  • 一些标准化的内部存储类,如Tuple <..>等。

  • Some custom collections, like Set<T>, Heap<T>, as well as plenty of utility methods for dealing with various types of collections
  • 一些自定义集合,如Set ,Heap ,以及用于处理各种类型集合的大量实用方法

The class library is added to when I need more stuff.

当我需要更多东西时,会添加类库。

#4


I'd suggest that instead of a "utility" library just make domain specific (graphics, authentication, validation, etc) libraries and only include them where they are needed. The key of course is decided how specific to be. More specificity is generally better.

我建议不要使用“实用程序”库来制作特定于域(图形,身份验证,验证等)的库,而只将它们包含在需要的地方。关键当然是决定具体是什么。更具特异性通常更好。

Irregardless if it has no domain then you probably don't understand it fully meaning that you should re-evaluate what you are doing and trying to accomplish first.

无论如果它没有域,那么你可能完全不理解它意味着你应该重新评估你正在做什么并试图先完成。

Also, remember that what is useful in one or two projects may end up only being useful in one or two projects. Adding more classes than necessary only causes maintenance issues down the road.

另外,请记住,在一个或两个项目中有用的东西最终只能用于一个或两个项目。添加超过必要的类只会导致维护问题。

#5


Though I am just a fledgling developer myself I have found RegEx functions and SQL filters to be quite useful. I also have Merge Replication functionality for MSSQL that has been quite handy for me so far.

虽然我自己只是一个初出茅庐的开发人员,但我发现RegEx函数和SQL过滤器非常有用。我也有MSSQL的合并复制功能,这对我来说非常方便。