/.NET-DataProtection-Extensions

Additions and extensions for .NET data-protection (ASP.NET Core).

Primary LanguageC#MIT LicenseMIT

.NET-DataProtection-Extensions

Additions and extensions for .NET data-protection (ASP.NET Core).

NuGet

1 Features

  • Configuring data-protection through AppSettings.json

1.1 Examples

1.1.1 Redis

Setup Redis locally with Docker:

docker run --rm -it -p 6379:6379 redis

2 Development

2.1 Data-protection with Azure

  • Haven't got it yet how the url should be composed.

2.2 Data-protection with database (EF)

2.2.1 Migrations (DataProtectionContext)

We might want to create/recreate migrations. If we can accept data-loss we can recreate the migrations otherwhise we will have to update them.

Copy all the commands below and run them in the Package Manager Console for the affected database-context.

If you want more migration-information you can add the -Verbose parameter:

Add-Migration TheMigration -Context TheDatabaseContext -OutputDir Data/Migrations -Project Project -StartupProject Application -Verbose;
2.1.1.1 Create migrations
Write-Host "Removing migrations...";
Remove-Migration -Context SqliteDataProtectionContext -Force -Project Project -StartupProject Application;
Remove-Migration -Context SqlServerDataProtectionContext -Force -Project Project -StartupProject Application;
Write-Host "Removing current migrations-directory...";
Remove-Item "Project\Data\Migrations" -ErrorAction Ignore -Force -Recurse;
Write-Host "Creating migrations...";
Add-Migration SqliteDataProtectionContextMigration -Context SqliteDataProtectionContext -OutputDir Data/Migrations/Sqlite -Project Project -StartupProject Application;
Add-Migration SqlServerDataProtectionContextMigration -Context SqlServerDataProtectionContext -OutputDir Data/Migrations/SqlServer -Project Project -StartupProject Application;
Write-Host "Finnished";
2.1.1.2 Update migrations
Write-Host "Updating migrations...";
Add-Migration SqliteCacheContextMigrationUpdate -Context SqliteDataProtectionContext -OutputDir Data/Migrations/Sqlite -Project Project -StartupProject Application;
Add-Migration SqlServerCacheContextMigrationUpdate -Context SqlServerDataProtectionContext -OutputDir Data/Migrations/SqlServer -Project Project -StartupProject Application;
Write-Host "Finnished";

2.3 Data-protection with Redis