Skip to content

Commit

Permalink
added IdentityErrorDescriber to AddMongoDbStores extension;
Browse files Browse the repository at this point in the history
updated dependencies;
version 8.2.0 release.
  • Loading branch information
vova3211 committed Jun 22, 2021
1 parent 2e839fb commit c801a96
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
13 changes: 7 additions & 6 deletions src/AspNetCore.Identity.Mongo/AspNetCore.Identity.Mongo.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@
<Authors>Matteo Fabbri</Authors>
<Company />
<Product>AspNetCore.Identity.Mongo</Product>
<Version>8.1.0</Version>
<AssemblyVersion>8.0.0.0</AssemblyVersion>
<FileVersion>8.0.0.0</FileVersion>
<Version>8.2.0</Version>
<AssemblyVersion>8.2.0.0</AssemblyVersion>
<FileVersion>8.2.0.0</FileVersion>
<PackageProjectUrl>https://github.com/matteofabbri/AspNetCore.Identity.Mongo</PackageProjectUrl>
<NeutralLanguage />
<PackageReleaseNotes>Added ability to set SslSettings and ClusterConfigurator.</PackageReleaseNotes>
<PackageReleaseNotes>improved performance;
added extension that allows register only mongodb stores.</PackageReleaseNotes>
<RunAnalyzersDuringBuild>false</RunAnalyzersDuringBuild>
<RunAnalyzersDuringLiveAnalysis>false</RunAnalyzersDuringLiveAnalysis>
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
Expand All @@ -28,8 +29,8 @@
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authentication" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Identity" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Identity.Core" Version="5.0.2" />
<PackageReference Include="Microsoft.Extensions.Identity.Stores" Version="5.0.2" />
<PackageReference Include="Microsoft.Extensions.Identity.Core" Version="5.0.7" />
<PackageReference Include="Microsoft.Extensions.Identity.Stores" Version="5.0.7" />
<PackageReference Include="MongoDB.Driver" Version="2.11.6" />
</ItemGroup>

Expand Down
17 changes: 9 additions & 8 deletions src/AspNetCore.Identity.Mongo/MongoStoreExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ namespace AspNetCore.Identity.Mongo
{
public static class MongoStoreExtensions
{
public static IdentityBuilder AddMongoDbStores<TUser>(this IdentityBuilder builder, Action<MongoIdentityOptions> setupDatabaseAction)
public static IdentityBuilder AddMongoDbStores<TUser>(this IdentityBuilder builder, Action<MongoIdentityOptions> setupDatabaseAction,
IdentityErrorDescriber identityErrorDescriber = null)
where TUser : MongoUser
{
return AddMongoDbStores<TUser, MongoRole, ObjectId>(builder, setupDatabaseAction);
return AddMongoDbStores<TUser, MongoRole, ObjectId>(builder, setupDatabaseAction, identityErrorDescriber);
}

public static IdentityBuilder AddMongoDbStores<TUser, TRole, TKey>(this IdentityBuilder builder, Action<MongoIdentityOptions> setupDatabaseAction)
public static IdentityBuilder AddMongoDbStores<TUser, TRole, TKey>(this IdentityBuilder builder, Action<MongoIdentityOptions> setupDatabaseAction,
IdentityErrorDescriber identityErrorDescriber = null)
where TKey : IEquatable<TKey>
where TUser : MongoUser<TKey>
where TRole : MongoRole<TKey>
Expand All @@ -30,12 +32,11 @@ public static IdentityBuilder AddMongoDbStores<TUser, TRole, TKey>(this Identity
setupDatabaseAction(dbOptions);

var migrationCollection = MongoUtil.FromConnectionString<MigrationHistory>(dbOptions, dbOptions.MigrationCollection);

Task.WaitAny(Migrator.Apply(migrationCollection));

var userCollection = MongoUtil.FromConnectionString<TUser>(dbOptions, dbOptions.UsersCollection);
var roleCollection = MongoUtil.FromConnectionString<TRole>(dbOptions, dbOptions.RolesCollection);

Migrator.Apply<TUser, TRole, TKey>(migrationCollection, userCollection, roleCollection);

builder.Services.AddSingleton(x => userCollection);
builder.Services.AddSingleton(x => roleCollection);

Expand All @@ -46,8 +47,8 @@ public static IdentityBuilder AddMongoDbStores<TUser, TRole, TKey>(this Identity
}

// Identity Services
builder.Services.AddTransient<IRoleStore<TRole>>(x => new RoleStore<TRole, TKey>(roleCollection));
builder.Services.AddTransient<IUserStore<TUser>>(x => new UserStore<TUser, TRole, TKey>(userCollection, new RoleStore<TRole, TKey>(roleCollection), x.GetService<ILookupNormalizer>()));
builder.Services.AddTransient<IRoleStore<TRole>>(x => new RoleStore<TRole, TKey>(roleCollection, identityErrorDescriber));
builder.Services.AddTransient<IUserStore<TUser>>(x => new UserStore<TUser, TRole, TKey>(userCollection, roleCollection, identityErrorDescriber));

return builder;
}
Expand Down

0 comments on commit c801a96

Please sign in to comment.