Click here to Skip to main content
15,892,161 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to synchronize codec. i have written same function in different controller and want to write that function in one place and call in anywhere in application so where to write that methods and how too access rather than repository.
Posted

1 solution

1.If the code is related with the same functionality in multiple controller, better is to create a base class for all your controller and keep your code only there. In this way you could have: protected, public or static methods that will be inherited in all your controllers.

I did in this way in my next MVC4 article: MVC Basic Site: Step 2 - Exceptions Management[^] All controller are inhering BaseController class.

2.In generally, if you want some global methods to be accessible into an entire context (assembly, application, solution) you should use static methods and place the methods into a public class and the class into a project (assembly) that is accessible into all projects that will need that common functionality.
 
Share this answer
 
v2
Comments
Member 9579525 1-Apr-14 3:38am    
thank u.
Raul Iloc 1-Apr-14 3:45am    
Welcome! If my solution helped you, you could accept it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900