Created
February 12, 2011 05:17
-
-
Save cammerman/823539 to your computer and use it in GitHub Desktop.
Autofac - keyed registration and IIndex dependencies.
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
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(); | |
} | |
} |
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
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