Skip to content

Instantly share code, notes, and snippets.

@cammerman
Created February 12, 2011 05:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cammerman/823539 to your computer and use it in GitHub Desktop.
Save cammerman/823539 to your computer and use it in GitHub Desktop.
Autofac - keyed registration and IIndex dependencies.
public class BootstrapIoC
{
public BootstrapIoC ()
{
}
public IContainer Build()
{
var builder = new ContainerBuilder();
builder
.RegisterType<Cache>()
.Keyed<ECacheType>(ECacheType.Thumb)
.As<ICache>()
.InstancePerLifetimeScope();
builder
.RegisterType<Cache>()
.Keyed<ECacheType>(ECacheType.Image)
.As<ICache>()
.InstancePerLifetimeScope();
builder
.RegisterType<ImageBrowser>()
.AsSelf()
.InstancePerLifetimeScope();
return builder.Build();
}
}
public class ImageBrowser
{
public virtual ICache ThumbCache
{
get;
private set;
}
public virtual ICache ImageCache
{
get;
private set;
}
public ImageBrowser(IIndex<ECacheType, ICache> caches)
{
ThumbCache = caches[ECacheType.Thumb];
ImageCache = caches[ECacheType.Image];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment