Has anything changed in mongodb c# driver for how to register an IIdGenerator?

396 Views Asked by At

I am currently trying to update my mongocsharpdriver package from version from 1.5 to 1.8.3. However my custom IdGenerator has stopped working with the upgrade.

The code I am using (with StructureMap) to register my id generator for all Ids of type int is:

For<MongoServer>()
    .Singleton()
    .Use(c =>
        {
            var server = MongoServer.Create(mongodbConnectionString);
            SequenceNumberRepository sequenceNumberRepository = new SequenceNumberRepository(server.GetDatabase("seq").GetCollection<Sequence>("seq"));                 
            IntegerIdGenerator integerIdGenerator = new IntegerIdGenerator(sequenceNumberRepository);
            // tell the BSON Serializer to use this generator when creating new integer ids
            BsonSerializer.RegisterIdGenerator(typeof(int), integerIdGenerator);    
            return server;
        });

The above has been working perfectly for many months on mongocsharpdriver 1.5. Today I tried to update our nuget package of mongocsharpdriver to 1.8.3 and I am now only getting Ids of 0 for any new items.

I put some break points in the IdGenerator's GenerateId and IsEmpty functions to see whats going on, but the functions aren't even being called (the constructor of the IdGenerator is called with the correct arguments, but not the actual functions when an item is inserted to the DB).

I looked up the documentation on http://docs.mongodb.org/ecosystem/tutorial/serialize-documents-with-the-csharp-driver/ about how to register an IdGenerator. There don't seem to be any differences documented on how to register an IdGenerator for a type.

Any help is appreciated

0

There are 0 best solutions below