Skip to content

Commit

Permalink
Refactor MongoConfigurator
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewgunn committed Sep 29, 2018
1 parent 53cd3a7 commit 3d6c853
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 31 deletions.
4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ for:
only:
- master

version: 0.2.1
version: 0.3.0

deploy:
- provider: Environment
Expand All @@ -38,4 +38,4 @@ for:
except:
- master

version: 0.2.1.{build}-{branch}
version: 0.3.0.{build}-{branch}
26 changes: 1 addition & 25 deletions src/Gunnsoft.IdentityServer.Stores.MongoDB/BsonClassMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,6 @@ namespace Gunnsoft.IdentityServer.Stores.MongoDB
{
public static class BsonClassMapper
{
public static void MapClient()
{
if (!BsonClassMap.IsClassMapRegistered(typeof(ClientDocument)))
{
BsonClassMap.RegisterClassMap<ClientDocument>(cm =>
{
cm.AutoMap();
cm.MapIdMember(c => c.Id);
cm.SetIgnoreExtraElements(true);
});
}
}

public static void MapPeristedGrant()
{
if (!BsonClassMap.IsClassMapRegistered(typeof(PersistedGrantDocument)))
{
BsonClassMap.RegisterClassMap<PersistedGrantDocument>(cm =>
{
cm.AutoMap();
cm.MapIdMember(c => c.Id);
cm.SetIgnoreExtraElements(true);
});
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ public static class IdentityServerBuilderExtensions
)
{
MongoConfigurator.ConfigureConventions();

BsonClassMapper.MapClient();
MongoConfigurator.ConfigureClientMapping();

var mongoClient = new MongoClient(mongoUrl);

Expand Down Expand Up @@ -52,8 +51,7 @@ await MongoConfigurator.ConfigureClientsCollectionAsync
)
{
MongoConfigurator.ConfigureConventions();

BsonClassMapper.MapPeristedGrant();
MongoConfigurator.ConfigurePeristedGrantMapping();

var mongoClient = new MongoClient(mongoUrl);

Expand Down
26 changes: 26 additions & 0 deletions src/Gunnsoft.IdentityServer.Stores.MongoDB/MongoConfigurator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,19 @@ await clientsCollection.Indexes.CreateManyAsync
);
}

public static void ConfigureClientMapping()
{
if (!BsonClassMap.IsClassMapRegistered(typeof(ClientDocument)))
{
BsonClassMap.RegisterClassMap<ClientDocument>(cm =>
{
cm.AutoMap();
cm.MapIdMember(c => c.Id);
cm.SetIgnoreExtraElements(true);
});
}
}

public static async Task ConfigurePersistedGrantsCollectionAsync
(
IMongoDatabase mongoDatabase,
Expand All @@ -67,6 +80,19 @@ await clientsCollection.Indexes.CreateManyAsync
}
}

public static void ConfigurePeristedGrantMapping()
{
if (!BsonClassMap.IsClassMapRegistered(typeof(PersistedGrantDocument)))
{
BsonClassMap.RegisterClassMap<PersistedGrantDocument>(cm =>
{
cm.AutoMap();
cm.MapIdMember(c => c.Id);
cm.SetIgnoreExtraElements(true);
});
}
}

private static async Task<bool> CollectionExistsAsync
(
IMongoDatabase mongoDatabase,
Expand Down

0 comments on commit 3d6c853

Please sign in to comment.