Saturday, October 1, 2011

Autofac and the Generic Repository Pattern

The Generic repository pattern is useful when you want to quickly get a site persisting its data elements without a lot of customization. Here is how I use the Generic Repository pattern (using MongoDB) with Dependency Injection (via Autofac).
builder.RegisterGeneric(typeof(MongoRepository<>))
    .WithParameter(new NamedParameter("connectionString", connectionString))
    .As(typeof(IRepository<>));

2 comments: