Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where do library classes go?

I do have experience with Ruby on Rails, and am programming a project in ASP.NET currently. So having found ASP.NET MVC was awesome for me, since it seems to be a verbatim copy of Ruby on Rails in many respects. However, there are differences, and I have to re-learn quite some things.

One such thing is the way additional (library) functionality is handled. I want to add an encryption utility functionality, and in Rails, I would just add a class to the /lib directory and know it would be available in my controllers. How do I do that in ASP.NET MVC?

I thought about creating a model class for this, but I'm not sure if that's the right way to go. All I really want is an encrypt(plain) and a decrypt(encrypted) function that return a string, I will use the .NET encryption libraries for the actual encryption and decryption, but want to encapsulate and proxy their functionality with easy-to-use functions available across multiple controllers.

Any suggestions?

like image 400
haslo Avatar asked Jul 01 '26 21:07

haslo


2 Answers

The best thing to do would be to create a second project that is simply a class library. Then reference this class library in your MVC application.

like image 104
Andrew Hare Avatar answered Jul 04 '26 03:07

Andrew Hare


Within your project you could add a folder called lib, or whatever, and put the code in there.

like image 26
Fermin Avatar answered Jul 04 '26 02:07

Fermin