Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Organizing c# project helper or utility classes

What are some best practices for where you should have helper classes in a .NET project? Referring to classes separate from business layer stuff, but presentation and app stuff like appSetting config managers and other code that would sometimes be module specific or sometimes be used throughout the app.

like image 542
spaghetticowboy Avatar asked Jul 29 '10 19:07

spaghetticowboy


People also ask

What are the two main ways a file can be organized in C?

Writing to a file (fprintf or fputs)

What is file structure C?

A FILE is a type of structure typedef as FILE. It is considered as opaque data type as its implementation is hidden. We don't know what constitutes the type, we only use pointer to the type and library knows the internal of the type and can use the data. Definition of FILE is in stdio although it is system specific.

What is C programming style?

C is an imperative procedural language supporting structured programming, lexical variable scope, and recursion, with a static type system. It was designed to be compiled to provide low-level access to memory and language constructs that map efficiently to machine instructions, all with minimal runtime support.


3 Answers

I always allow things like this to be pretty fluid. That said:

  1. I test "helper" classes the same as any other class. This makes them tend to not be static.
  2. I may start by creating these helpers as individual methods when needed. As I find they are needed in more than one class, I'll move them into their own class or a "Utilities" class in the same project.
  3. If I find they are needed in more than one project, then I move them higher up in the "hierarchy": from project to solution, from solution to subsystem, from subsystem to application, from application to library or framework, etc.
like image 128
John Saunders Avatar answered Sep 19 '22 11:09

John Saunders


I tend to put them in a utils namespace. Either in the mainproject namespace if they are pretty general e.g. MyProject.Utils.MyHelperClass, or if they are more specific then a sub namespace MyProject.CRM.Utils.MyCRMHelperClass.

like image 39
Ben Robinson Avatar answered Sep 19 '22 11:09

Ben Robinson


I almost always have a MyProject.Core class library in my solution where I put things like that.

Edit: I might have answered a "bigger" question.

In a single project it all depends on the size of the project. The Microsoft Design Guidelines talks about that you shouldn't create a namespace if you have less then five(correct me if I'm wrong about this number) types within it.

like image 23
Jesper Palm Avatar answered Sep 19 '22 11:09

Jesper Palm