Skip to content

Commit 48a72f2

Browse files
Provide Microsoft.AspNetCore.DataProtection.EntityFrameworkCore package README (#57823)
1 parent 6b6f5a2 commit 48a72f2

File tree

1 file changed

+45
-0
lines changed
  • src/DataProtection/EntityFrameworkCore/src

1 file changed

+45
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
## About
2+
3+
`Microsoft.AspNetCore.DataProtection.EntityFrameworkCore` provides a mechanism for storing data protection keys to a database using Entity Framework Core.
4+
5+
## How to Use
6+
7+
To use `Microsoft.AspNetCore.DataProtection.EntityFrameworkCore`, follow these steps:
8+
9+
### Installation
10+
11+
```shell
12+
dotnet add package Microsoft.AspNetCore.DataProtection.EntityFrameworkCore
13+
```
14+
15+
### Configuration
16+
17+
To store keys in a database, use the `PersistKeysToDbContext` extension method. For example:
18+
19+
```csharp
20+
builder.Services.AddDataProtection()
21+
.PersistKeysToDbContext<MyDbContext>();
22+
```
23+
24+
Ensure that your DB context (`MyDbContext` in the above example) implements `IDataProtectionKeyContext`. For example:
25+
26+
```csharp
27+
class MyDbContext : DbContext, IDataProtectionKeyContext
28+
{
29+
public MyKeysContext(DbContextOptions<MyKeysContext> options)
30+
: base(options)
31+
{
32+
}
33+
34+
// This maps to the table that stores keys
35+
public DbSet<DataProtectionKey> DataProtectionKeys { get; set; }
36+
}
37+
```
38+
39+
## Additional Documentation
40+
41+
For additional documentation and examples, refer to the [official documentation](https://learn.microsoft.com/aspnet/core/security/data-protection/implementation/key-storage-providers#entity-framework-core) on the Entity Framework Core key storage provider.
42+
43+
## Feedback &amp; Contributing
44+
45+
`Microsoft.AspNetCore.DataProtection.EntityFrameworkCore` is released as open-source under the [MIT license](https://licenses.nuget.org/MIT). Bug reports and contributions are welcome at [the GitHub repository](https://github.com/dotnet/aspnetcore).

0 commit comments

Comments
 (0)