More documentation improvements.
This commit is contained in:
@@ -13,26 +13,41 @@ public class AppUser : Raven.Identity.IdentityUser
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
2. In Startup.cs:
|
2. In appsettings.json, configure your connection to Raven:
|
||||||
|
|
||||||
|
```json
|
||||||
|
"RavenSettings": {
|
||||||
|
"Urls": [
|
||||||
|
"http://live-test.ravendb.net"
|
||||||
|
],
|
||||||
|
"DatabaseName": "Raven.Identity.Sample",
|
||||||
|
"CertFilePath": "",
|
||||||
|
"CertPassword": ""
|
||||||
|
},
|
||||||
|
```
|
||||||
|
|
||||||
|
3. In Startup.cs, wire it all up:
|
||||||
|
|
||||||
```csharp
|
```csharp
|
||||||
public void ConfigureServices(IServiceCollection services)
|
public void ConfigureServices(IServiceCollection services)
|
||||||
{
|
{
|
||||||
// Grab our RavenSettings object from appsettings.json.
|
// Grab our RavenSettings object from appsettings.json.
|
||||||
services.Configure<RavenSettings>(Configuration.GetSection("RavenSettings"));
|
services.Configure<RavenSettings>(Configuration.GetSection("RavenSettings"));
|
||||||
|
|
||||||
// Add RavenDB and identity.
|
...
|
||||||
services
|
|
||||||
.AddRavenDbDocStore() // Create an IDocumentStore singleton from the RavenSettings.
|
// Add RavenDB and identity.
|
||||||
.AddRavenDbAsyncSession() // Create a RavenDB IAsyncDocumentSession for each request. docStore is your IDocumentStore instance. You're responsible for calling .SaveChanges after each request.
|
services
|
||||||
.AddRavenDbIdentity<AppUser>(); // Use Raven to manage users and roles.
|
.AddRavenDbDocStore() // Create an IDocumentStore singleton from the RavenSettings.
|
||||||
|
.AddRavenDbAsyncSession() // Create a RavenDB IAsyncDocumentSession for each request. docStore is your IDocumentStore instance. You're responsible for calling .SaveChanges after each request.
|
||||||
...
|
.AddRavenDbIdentity<AppUser>(); // Use Raven to manage users and roles.
|
||||||
|
|
||||||
|
...
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
3. In your controller actions, call .SaveChanges when you're done making changes. Typically this is done via a RavenController base class for MVC/WebAPI projects, or via an [ActionFilter](https://github.com/JudahGabriel/RavenDB.Identity/blob/master/Sample/Filters/RavenSaveChangesAsyncFilter.cs) for Razor Pages projects.
|
4. In your controller actions, call .SaveChangesAsync() when you're done making changes. Typically this is done via a RavenController base class for MVC/WebAPI projects or via an action filter. See our Sample [RavenSaveChangesAsyncFilter.cs](https://github.com/JudahGabriel/RavenDB.Identity/blob/master/Sample/Filters/RavenSaveChangesAsyncFilter.cs).
|
||||||
|
|
||||||
Need help? See the [sample app](https://github.com/JudahGabriel/RavenDB.Identity/tree/master/Sample) to see it all in action.
|
Need help? Checkout the [sample app](https://github.com/JudahGabriel/RavenDB.Identity/tree/master/Sample) to see it all in action.
|
||||||
|
|
||||||
Not using .NET Core? See our [sister project](https://github.com/JudahGabriel/RavenDB.AspNet.Identity) for a RavenDB Identity Provider for MVC 5+ and WebAPI 2+ on the full .NET Framework.
|
Not using .NET Core? See our [sister project](https://github.com/JudahGabriel/RavenDB.AspNet.Identity) for a RavenDB Identity Provider for the full .NET Framework.
|
||||||
+10
-9
@@ -3,10 +3,10 @@
|
|||||||
This is a Razor Pages sample that shows how to use Raven.Identity.
|
This is a Razor Pages sample that shows how to use Raven.Identity.
|
||||||
|
|
||||||
There are four areas of interest:
|
There are four areas of interest:
|
||||||
1. appsettings.json - where we configure our connection to Raven.
|
1. [appsettings.json](https://github.com/JudahGabriel/RavenDB.Identity/blob/master/Sample/appsettings.json) - where we configure our connection to Raven.
|
||||||
2. AppUser.cs - our user class containing any user data like FirstName and LastName.
|
2. [AppUser.cs](https://github.com/JudahGabriel/RavenDB.Identity/blob/master/Sample/Models/AppUser.cs) - our user class containing any user data like FirstName and LastName.
|
||||||
3. RavenSaveChangesAsyncFilter.cs - where we save changes to Raven after actions finish executing. This makes sense for a Razor Pages project. For an MVC or Web API project, use a RavenController base class instead.
|
3. [RavenSaveChangesAsyncFilter.cs](https://github.com/JudahGabriel/RavenDB.Identity/blob/master/Sample/Filters/RavenSaveChangesAsyncFilter.cs) - where we save changes to Raven after actions finish executing. This makes sense for a Razor Pages project. For an MVC or Web API project, use a RavenController base class instead.
|
||||||
4. Startup.cs - where we wire up everything
|
4. [Startup.cs](https://github.com/JudahGabriel/RavenDB.Identity/blob/master/Sample/Startup.cs) - where we wire up everything.
|
||||||
|
|
||||||
More details below.
|
More details below.
|
||||||
|
|
||||||
@@ -43,7 +43,7 @@ While this step isn't strictly necessary -- it's possible to skip AppUser and ju
|
|||||||
|
|
||||||
## 3. RavenSaveChangesAsyncFilter
|
## 3. RavenSaveChangesAsyncFilter
|
||||||
|
|
||||||
In Startup.cs (next step), we'll tell AspNetCore to create an `IAsyncDocumentSession` for every request. But we need to `.SaveChangesAsync()` for anything to persist in Raven.
|
We need to `.SaveChangesAsync()` for anything to persist in Raven. Where should we do this?
|
||||||
|
|
||||||
While we could call `.SaveChangesAsync()` in the code-behind of every Razor page, that is tedious and error prone. Instead, we create a Razor action filter to save changes, [RaveSaveChangesAsyncFilter.cs](https://github.com/JudahGabriel/RavenDB.Identity/blob/master/Sample/Filters/RavenSaveChangesAsyncFilter.cs):
|
While we could call `.SaveChangesAsync()` in the code-behind of every Razor page, that is tedious and error prone. Instead, we create a Razor action filter to save changes, [RaveSaveChangesAsyncFilter.cs](https://github.com/JudahGabriel/RavenDB.Identity/blob/master/Sample/Filters/RavenSaveChangesAsyncFilter.cs):
|
||||||
|
|
||||||
@@ -90,6 +90,8 @@ public void ConfigureServices(IServiceCollection services)
|
|||||||
// Grab our RavenSettings object from appsettings.json.
|
// Grab our RavenSettings object from appsettings.json.
|
||||||
services.Configure<RavenSettings>(Configuration.GetSection("RavenSettings"));
|
services.Configure<RavenSettings>(Configuration.GetSection("RavenSettings"));
|
||||||
|
|
||||||
|
...
|
||||||
|
|
||||||
// Add an IDocumentStore singleton, with settings pulled from the RavenSettings.
|
// Add an IDocumentStore singleton, with settings pulled from the RavenSettings.
|
||||||
services.AddRavenDbDocStore();
|
services.AddRavenDbDocStore();
|
||||||
|
|
||||||
@@ -98,10 +100,9 @@ public void ConfigureServices(IServiceCollection services)
|
|||||||
services.AddRavenDbAsyncSession();
|
services.AddRavenDbAsyncSession();
|
||||||
|
|
||||||
// Use Raven for our users
|
// Use Raven for our users
|
||||||
var identityModel = services.AddRavenDbIdentity<AppUser>();
|
services.AddRavenDbIdentity<AppUser>();
|
||||||
|
|
||||||
// Optional: some default Razor Pages UI for login/register/forgot password/etc.
|
...
|
||||||
identityBuilder.AddDefaultUI(UIFramework.Bootstrap4);
|
|
||||||
|
|
||||||
// Call .SaveChangesAsync() after each action.
|
// Call .SaveChangesAsync() after each action.
|
||||||
services
|
services
|
||||||
|
|||||||
Reference in New Issue
Block a user