그래서 자동 차단을 사용하면서 차단 개념을 구현하려고합니다. 역동적 인 인터셉트를 구현하는 것과 같은 구체적인 것은하지 않습니다. 모든 클래스에 구체적인 코드가 있습니다.자동 차단 (AutoFac) 차단, 내부를 외부와 구분하는 방법
내 코드 (나의 실제 코드는,이 온라인을 발견하지만 내 문제가
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;
}
}
, 내 ProductManager이 IProductService에 대해 "CachedProductService"을 수신 할 내 문제를 보여줍니다, 그리고 내 CachedProductService을 원한다 IProductService에 대한 "DefaultProductService"를받을 수 있습니다.
을 나는 몇 가지 해결책을 알고 있지만, 그들 중 누구도 정확히 올바른 보이지 않는다. 어떻게이 일을 올바른 방법인가?
감사합니다! 마이클
귀하의'CachedProductService'는 데코레이터입니다 : http://docs.autofac.org/en/latest/advanced/adapters-decorators.html. – Steven