Version 6.0.0 of the AuthPermissions.AspNetCore library (shortened to AuthP from now on) contains improved sharding features, but these changes contain BREAKING CHANGES, but they ONLY EFFECT multi-tenant applications that use sharding, i.e. you have the SetupMultiTenantSharding
extension method in your AuthP registration code.
These breaking changes came about because of a limitation found in the ASP.NET Core IOptions
feature. However, when I was working on the data that links tenants to databases (now called sharding entries) I found my previous code didn't use nice names. For instance:
- The name of a class, method, etc didn't match what it was used for. For instance the class that links a tenant to a database was called
DatabaseInformation
, but its name is now its calledShardingEntry
. - Some method names were too long. For instance the method that updated a
ShardingEntry
was calledUpdateDatabaseInfoToShardingInformation
and now calledUpdateShardingEntry
.
Of course this creates more breaking changes, but the code will be easier to understand. Also on upgrading to AuthP 6 it will be very obvious, as each change will become an error.
- Changing to the new IGetSetShardingEntries service.
- Updating the IGetSetShardingEntries method names
- Make sure that distributed FileStore Cache is registered
- Move your AuthP 5 sharding entries to the AuthP 6 FileStore Cache
- Register the FileStore Cache (if not already there)
The subsections below the items listed in the table of content.
1. Changing to the new IGetSetShardingEntries service
Before AuthP version 6 you had two services called IAccessDatabaseInformationVer5
and IShardingConnections
. Now you have one service called IGetSetShardingEntries
that contains all the methods, properties, etc. that the two services it replaces.
Old name | new name | Notes |
---|---|---|
IAccessDatabaseInformationVer5 |
IGetSetShardingEntries |
I use shardingService |
IShardingConnections |
IGetSetShardingEntries |
I use shardingService |
The other big change is IGetSetShardingEntries
changes the name of a class
Old name | new name | Notes |
---|---|---|
DatabaseInformation |
ShardingEntry |
The table below gives the old and new.
Old name | new name | Notes |
---|---|---|
ReadAllShardingInformation |
GetAllShardingEntries |
|
GetDatabaseInformationByName |
GetSingleShardingEntry |
|
AddDatabaseInfoToShardingInformation |
AddNewShardingEntry |
|
UpdateDatabaseInfoToShardingInformation |
UpdateShardingEntry |
|
RemoveDatabaseInfoFromShardingInformationAsync |
RemoveShardingEntry |
|
GetAllPossibleShardingData |
GetAllShardingEntries |
|
GetDatabaseInfoNamesWithTenantNamesAsync |
GetShardingsWithTenantNamesAsync |
A properly that has been simplified.
Old name | new name | Notes |
---|---|---|
ShardingDatabaseProviders.Keys.ToArray() |
PossibleDatabaseProviders |
Other IShardingConnections
methods that haven't changed are listed below.
Old name | new name | Notes |
---|---|---|
GetConnectionStringNames |
GetConnectionStringNames |
No change |
Once your code complies with AuthP version 6 and before you run your application you need to move your sharding entries from the AuthP's version 5 json file to AuthP's version 6 distributed FileStore Cache. There is a Console app called ConsoleApp.AuthP6Upgrade
within the AuthP's repo that will copy any sharding entries from the AuthP's version 5's json file into the AuthP version 6's Distributed FileStore Cache.
To use the the ConsoleApp.AuthP6Upgrade you could:
- Clone the AuthP's repo and to gain access to the console app that way.
- You could create a ConsoleApp and copy the
ConsoleApp.AuthP6Upgrade.Program
code into your Program class. You will need the following NuGet packages:- AuthPermissions.AspNetCore
- Net.DistributedFileStoreCache
This console app needs three parameters:
- The filepath to the the json file. This can be a relative or absolute.
- The name of the json file holding the AuthP version 5 sharding entries, e.g. "shardingsettings.Production.json"
- The name for the new FileStore Cache file used by AuthP version 6, e.g. "FileStoreCacheFile.Production.json".
Here is an example of running this on a Window's command prompt.
C:> dotnet run ...Example6.MvcWebApp.Sharding shardingsettings.Development.json FileStoreCacheFile.Production.json
Added the sharding entry with the name of 'Default Database' added to the FileStore
Added the sharding entry with the name of 'DatabaseWest1' added to the FileStore
Added the sharding entry with the name of 'DatabaseEast1' added to the FileStore
Successfully copied 3 sharding entry to the FileStore Cache called 'FileStoreCacheFile.Production.json'.
C:>
This console app will store the sharding entries in the FileStore Cache using a format which makes it easier to to read (but is slightly slower). But when your application adds / changes an sharding entry it will use your applications's setup of the DistributedFileStoreCache will take over and the default settings means it stored more compactly, which is faster.
The default implementation of the `IGetSetShardingEntries service uses the Net.DistributedFileStoreCache. Therefore you need to make sure that you have registered the DistributedFileStoreCache during startup - see the Register the DistributedFileStoreCache document.
NOTE: You might already registered for another use, like "down for maintenance" feature.
END