Reputation: 14746
I have an MVC4 project that calls a business layer method whose current signature is as below:
businessObject.BusinessMethod(param1, param2, param3)
In this business layer method I now need to have some data from the HttpContext.Current.Session["SomeSessionValue"]
property.
So instead of adding two more parameters using Resharpers refactoring feature, I want to club all of those three into an object and rename the signature as below
businessObject.BusinessMethod(myParametersObject)
This business layer method is used all over the solution and is tested code. If I use resharper to modify the method signature, I will now need to assign the values of param1, param2, param3 to the respective properties within the MyParameters class's object before calling the method businessObject.BusinessMethod(myParametersObject)
There are over 2000 places I need to make this change. Is there a faster way to make this change? I don't want to manually change the code everywhere or add the HttpContext to the business layer. Can some OOP technique help me out here?
Thanks.
Upvotes: 0
Views: 1299
Reputation: 131581
Using the HttpContext object to pass a global object is a bad idea. Normally, the business layer shouldn't even have a reference to System.Web.
Resharper has the "Extract Class from Parameters ..." refactoring to automate what you describe. You can access it by right-clicking on your method's name and choose Refactor > Extract > Extract Class from Parameters. You can then select the parameters you want to include in the class.
Resharper will update all references to the method to create and use the new class.
In any case, more than 3 or 4 parameters is a code smell that suggests the method may be trying to do too many things. When you cross that threshold it's time to change your design and either consolidate the parameters or split the method.
Upvotes: 2