Вопрос

I have a C# Class Library project that is referenced by many different Line of Business solutions, let's call it MyCompanyUtilities. MyCompanyUtilities contains database access code, code for retrieving data from our ERP system about our employees, useful extension methods, code to send emails etc.

Occasionally, I want to refactor the code in MyCompanyUtilities, which would sometimes introduce breaking changes in other projects. As an example use case, let's say I want to rename a function from:

public static User Load(string employeeId){}

to

public static User LoadByEmployeeId(string employeeId){}

Obviously, the rationale for such a change is that now I can also implement methods with a similar signature.

public static User LoadByPersonId(string personId) {}

However, how do I go about updating ALL the other solutions/projects that might be using the previous function call? I have at least 30+ projects/solutions that reference MyCompanyUtilities. I am using Visual Studio 2010 Professional.

Это было полезно?

Решение

If anyone comes across this question in the future, I solved this using NuGet. I created a private NuGet repository to host my MyCompanyUtilities. Now my various solutions can reference specific versions of the utilities, and when I open those solutions I can choose to upgrade to a newer version of the utilities. No, it doesn't automatically refactor all the solutions, but at least I don't get breaking changes when I load a new project unless I opt to update to a newer version of the utilities.

Другие советы

The name of a method does not reveal its purpose. In the specific case I will change the old method to this:

public static User Load(string employeeId){
    return LoadByPersonId(string personId);
}

then i will mark old method:

[Obsolete("Load is deprecated, please use LoadByPersonId instead.")]

Renaming Refactoring Across Multiple Solutions:

Actually there is no straightforward way to achieve this, as the solutions may be present in your local disk drive, or those may be split in between your local machine and remote ones, perhaps may be in source control system, Visual Studio or any other refactoring tools will have little knowledge about them. But wait...some tweaks may sometimes work for this.

You may create a root solution containing the referenced project(MyCompanyUtilities) and all other dependent projects from different solutions in one place. Then the naive Rename Refactoring technique may be enough for the case. When the required refactoring is complete, you need to copy back the projects to their parent solutions either manually or with the help of something like batch commands.

Digging to further refactoring...As you have said that your MyCompanyUtilities contains database access code, code for retrieving data from your ERP system about our employees, useful extension methods, code to send emails etc. I would suggest you to pull out all the UI and Database related code from MyCompanyUtilities, if it contains such. Then you'd be able to change the front-end UI(e.g. Desktop <-> Web <-> Mobile <-> Cloud) and back-end Database(e.g. MSSQL <-> SQLite <-> Oracle <-> MySQL) easily whenever your company has any business requirement to do so.

In a sentence, separate the code that changes from the one which does not change.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top