CG.Business – Breaking Changes

CG.Business – Breaking Changes

I recently made a change to the code that locates and loads repository and strategy types, inside the CG.Business library. The new changes accomplish three things:

  1. They fix a problem with assembly loading, created when I located the ‘AssemblyNameOrPath’ key in an awkward place. The new location makes more sense, and also fixes a problem I had with loading multiple assemblies, at startup.
  2. They fix an unfortunate naming scheme for the configuration key that identifies which repository / strategy to load at startup. The old key was named ‘Name’. The new key is named ‘Selected’. I like the new key better because it more clearly communicates the purpose of the key.
  3. They add the ability to cleanly load single or multiple repositories / strategies. The ‘Selected’ key can now contain either a single string value or an array of string values, where each value is the name of a particular repository / strategy.

Unfortunately, all this means I probably broke some things. The good news is, the process to migrate to the newer format is easy and I’ll walk everyone through it here.

The first step is to update your existing project to use the latest version of CG.Business. To do that, open the NUGET manager, inside Visual Studio. Go the Update tab, find CG.Business, then press the “Update” button.

The next step is to edit the appSettings.json file, for your project. Now this step will depend greatly on the actual format of your JSON, which I can’t predict. I can, how ever, say there anywhere you had a section for loading a repository / strategy, like this:

{
   "Foo": {
      "Name": "A",
      "AssemblyNameOrPath": "",
      "A" : {
        // whatever your section looks like ...
      }
   }
}

Should be changed to look more like this:

{
   "Foo": {
      "Selected": "A",
      "A" : {
         "AssemblyNameOrPath" : "", 
        // whatever your section looks like ...
      }
   }
}

Note that I changed the Name key to Selected. I also moved the AssemblyNameOrPath key/value down into the A section. That’s because the assembly we’re loading there is specifically for the repository / strategy associated with the A section.

If you’re needs include loading multiple repository / strategy instances at once, then good news! It’s now super easy to support that in your configuration. Do something like this:

{
   "Foo": {
      "Selected": ["A", "B" ],
      "A" : {
         "AssemblyNameOrPath" : "", 
        // whatever your section looks like ...
      },
    "B" : {
       "AssemblyNameOrPath": "",
       // whatever your section looks like ...
    }
   }
}

No code changes are required, on your part, to support this version. The only change was to the JSON format, for the configuration.

As always, the source for the CG.Business library is available HERE.

The package itself is available HERE.

Photo by Ivan Vranić on Unsplash