Created
May 15, 2011 04:54
-
-
Save cammerman/972896 to your computer and use it in GitHub Desktop.
Sample desired syntax for declarative definition of bound lifetime scopes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Container context tags | |
enum EContainerContext | |
{ | |
UnitOfWork, | |
Plugin, | |
MultiInstanceWindow | |
} | |
// Registration code for an object that owns a lifetime scope | |
builder.RegisterType<MyDbContext>() | |
.As<DbContext>(); | |
builder.RegisterType<UnitOfWork>() // Has dependency on DbContext. | |
.As<IUnitOfWork>() | |
.EstablishesLifetimeScope() // Desired syntax. Indicates each new UnitOfWork should have a new lifetime scope bound to the life of the object. Also implies the UnitOfWork itself has per-dependency lifetime scope. Each time requested outside the bound lifetime scope, a new one is created. | |
.WithTag(EContainerContext.UnitOfWork); // Desired syntax. Specifies the tag to attach to the generated lifetime scope. | |
builder.RegisterType<DomainType1Repository>() // Has dependency on IUnitOfWork. | |
.As<IRepository<DomainType1>>() | |
.InstancePerMatchingLifetimeScope(EContainerContext.UnitOfWork); | |
builder.RegisterType<DomainType2Repository>() // Has dependency on IUnitOfWork. | |
.As<IRepository<DomainType2>>() | |
.InstancePerMatchingLifetimeScope(EContainerContext.UnitOfWork); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment