From f974fbe399e0298d18b178c4da88a345b6181ac9 Mon Sep 17 00:00:00 2001 From: Judah Himango CW Date: Mon, 4 Mar 2019 17:11:14 -0600 Subject: [PATCH] More documentation improvements. --- Readme.md | 41 ++++++++++++++++++++++++++++------------- Sample/Readme.md | 19 ++++++++++--------- 2 files changed, 38 insertions(+), 22 deletions(-) diff --git a/Readme.md b/Readme.md index a09613b..05e7151 100644 --- a/Readme.md +++ b/Readme.md @@ -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 public void ConfigureServices(IServiceCollection services) { - // Grab our RavenSettings object from appsettings.json. + // Grab our RavenSettings object from appsettings.json. services.Configure(Configuration.GetSection("RavenSettings")); - - // Add RavenDB and identity. - services - .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(); // Use Raven to manage users and roles. - - ... + + ... + + // Add RavenDB and identity. + services + .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(); // 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. \ No newline at end of file +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. \ No newline at end of file diff --git a/Sample/Readme.md b/Sample/Readme.md index 2445a76..062e1d0 100644 --- a/Sample/Readme.md +++ b/Sample/Readme.md @@ -3,10 +3,10 @@ This is a Razor Pages sample that shows how to use Raven.Identity. There are four areas of interest: - 1. appsettings.json - where we configure our connection to Raven. - 2. 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. - 4. Startup.cs - where we wire up everything + 1. [appsettings.json](https://github.com/JudahGabriel/RavenDB.Identity/blob/master/Sample/appsettings.json) - where we configure our connection to Raven. + 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](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](https://github.com/JudahGabriel/RavenDB.Identity/blob/master/Sample/Startup.cs) - where we wire up everything. More details below. @@ -43,7 +43,7 @@ While this step isn't strictly necessary -- it's possible to skip AppUser and ju ## 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): @@ -90,6 +90,8 @@ public void ConfigureServices(IServiceCollection services) // Grab our RavenSettings object from appsettings.json. services.Configure(Configuration.GetSection("RavenSettings")); + ... + // Add an IDocumentStore singleton, with settings pulled from the RavenSettings. services.AddRavenDbDocStore(); @@ -98,10 +100,9 @@ public void ConfigureServices(IServiceCollection services) services.AddRavenDbAsyncSession(); // Use Raven for our users - var identityModel = services.AddRavenDbIdentity(); - - // Optional: some default Razor Pages UI for login/register/forgot password/etc. - identityBuilder.AddDefaultUI(UIFramework.Bootstrap4); + services.AddRavenDbIdentity(); + + ... // Call .SaveChangesAsync() after each action. services