Created
February 11, 2011 05:47
-
-
Save cammerman/821979 to your computer and use it in GitHub Desktop.
Cache registrations 2
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
builder | |
.RegisterType<Cache>() | |
.As<ICache>() | |
.WithMetadata("CacheType", ECacheType.Thumb) | |
.InstancePerLifetimeScope(); | |
builder | |
.RegisterType<Cache>() | |
.As<ICache>() | |
.WithMetadata("CacheType", ECacheType.Image) | |
.InstancePerLifetimeScope(); |
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
using System; | |
using System.Linq; | |
using System.Collections.Generic; | |
using Autofac.Features.Metadata; | |
namespace HowILearnedToLoveKeyedDependencies | |
{ | |
public class ImageBrowser | |
{ | |
public virtual ICache ThumbCache | |
{ | |
get; | |
private set; | |
} | |
public virtual ICache ImageCache | |
{ | |
get; | |
private set; | |
} | |
protected virtual Func<Meta<ICache>, Boolean> CacheTypeChecker(ECacheType cacheType) | |
{ | |
return | |
cache => | |
cache.Metadata["CacheType"] | |
.Equals(cacheType); | |
} | |
public ImageBrowser(IEnumerable<Meta<ICache>> caches) | |
{ | |
ThumbCache = | |
caches | |
.First(CacheTypeChecker(ECacheType.Thumb)) | |
.Value; | |
ImageCache = | |
caches | |
.First(CacheTypeChecker(ECacheType.Image)) | |
.Value; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment