I thought I would share some code of how my SisoDb (Simple-Structure-Oriented-Db) looks like.
As of right now you have to provide info about which member contains the key. This will change and will instead be convention based.
var schemaBuilder = new ManualSchemaBuilder(); schemaBuilder.Register<Customer>(builder => builder.SetKey(c => c.Id));
You can also use SchemaBuilder.AddIndex to provide specific indexes that you wan’t to query more efficiently.
var schemaBuilder = new ManualSchemaBuilder();
schemaBuilder.Register<Customer>(
builder => builder
.SetKey(c => c.Id)
.AddIndex(c => c.Lastname));
The next step is to create a database. Supported options are I/O-based or a Virtual (in-memory) database. The virtual only lasts as long as the UnitOfWork lives. The database is designed to be long-lived and is something you would keep alive, preferable using your IoC-container.
var connectionInfo = new LuceneConnectionInfo(LuceneDbTypes.Io, @"C:\#Temp\SisoDb\ConsoleSample"); var database = new LuceneDatabase(connectionInfo); var schemas = schemaBuilder.GetSchemas(); database.RegisterSchemas(schemas);
Now we are ready to add some data, so lets create a Customer and add it using UnitOfWork
var customer = new Customer
{
Firstname = "Daniel",
Lastname = "Wertheim",
ShoppingIndex = ShoppingIndexes.Level1,
CustomerSince = DateTime.Now
};
using (var unitOfWork = database.CreateUnitOfWork())
{
unitOfWork.Insert(customer);
unitOfWork.Commit();
}
That’s it. If Commit() isn’t called everything is rolled back.
I will soon publish the source code on Google Code.
//Daniel