Skip to content

Instantly share code, notes, and snippets.

@droyad
Last active December 11, 2015 12:38
Show Gist options
  • Select an option

  • Save droyad/4602086 to your computer and use it in GitHub Desktop.

Select an option

Save droyad/4602086 to your computer and use it in GitHub Desktop.
protected override void Load(ContainerBuilder builder)
{
builder.Register(CreatedDbFunc).As<Func<Owned<IDb>>>().InstancePerDependency();
builder.Register(c => CreatedDbWithConnectionFunc()).As<Func<DbConnection, Owned<IDb>>>().InstancePerDependency();
builder.RegisterType<CurrentDatabase>().InstancePerMatchingLifetimeScope(LifetimeScopes.Workspace);
}
private Func<Owned<IDb>> CreatedDbFunc(IComponentContext context)
{
var currentDbFunc = context.Resolve<Func<CurrentDatabase>>();
return () =>
{
var db = new Db(currentDbFunc());
return new Owned<IDb>(db, db);
};
}
private Func<DbConnection, Owned<IDb>> CreatedDbWithConnectionFunc()
{
return connection =>
{
var db = new Db(connection);
return new Owned<IDb>(db, db);
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment