Skip to content

Commit 7c660ed

Browse files
committed
Merge pull request #11 from assaframan/master
Fixed a "the chicken and the egg paradox": If you get an exception in the constructor - you will not be able to call functions of the class later on.
2 parents 6a85970 + 0090b6c commit 7c660ed

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

src/ServiceStack.Authentication.MongoDB/MongoDBAuthRepository.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,19 @@ private static string Counters_Col
5252
}
5353
}
5454

55-
public MongoDBAuthRepository(MongoDatabase mongoDatabase)
55+
public MongoDBAuthRepository(MongoDatabase mongoDatabase, bool createMissingCollections)
5656
{
5757
this.mongoDatabase = mongoDatabase;
5858

59+
if (createMissingCollections)
60+
{
61+
CreateMissingCollections();
62+
}
63+
5964
if (!CollectionsExists())
6065
{
6166
throw new InvalidOperationException("One of the collections needed by MongoDBAuthRepository is missing." +
62-
"You can call CreateMissingCollections or DropAndReCreateCollections " +
67+
"You can call MongoDBAuthRepository constructor with the parameter CreateMissingCollections set to 'true' " +
6368
"to create the needed collections.");
6469
}
6570
}

0 commit comments

Comments
 (0)