したがって、autofacを使用している間、傍受の概念を実装しようとしています。ダイナミックな傍受を実装するのと同じように、私は具体的なコードを持っているすべてのクラスのように、何も気にしません。AutoFacインターセプト、内部と外部を区別する方法
マイコード(ない私の実際のコードは、私はこのオンラインを見つけたが、それは私の問題は、私は私のプロダクトマネージャーは、IProductServiceのための「CachedProductService」を受信したい、と私は私のCachedProductServiceをしたい、ある
public class DefaultProductService : IProductService
{
public Product GetProduct(int productId)
{
return new Product();
}
}
public class CachedProductService : IProductService
{
private readonly IProductService _innerProductService;
private readonly ICacheStorage _cacheStorage;
public CachedProductService(IProductService innerProductService, ICacheStorage cacheStorage)
{
if (innerProductService == null) throw new ArgumentNullException("ProductService");
if (cacheStorage == null) throw new ArgumentNullException("CacheStorage");
_cacheStorage = cacheStorage;
_innerProductService = innerProductService;
}
public Product GetProduct(int productId)
{
string key = "Product|" + productId;
Product p = _cacheStorage.Retrieve<Product>(key);
if (p == null)
{
p = _innerProductService.GetProduct(productId);
_cacheStorage.Store(key, p);
}
return p;
}
}
public class ProductManager : IProductManager
{
private readonly IProductService _productService;
public ProductManager(IProductService productService)
{
_productService = productService;
}
}
私の問題を示していますIProductServiceのための「DefaultProductService」を受信する。
を私はいくつかの解決策を知っているが、それらのどれも正確に正しいようではありません。これを行うための正しい方法は何ですか?
ありがとう! マイケル
あなたの 'CachedProductService'はデコレータです:http://docs.autofac.org/en/latest/advanced/adapters-decorators.html。 – Steven