Castle Windsor - 如何创建安装程序来处理多级依赖结构

Castle Windsor - How to create an installer to deal with multi level dependency structures

我有几个不同的 classes 从同一个接口继承的情况。此外,有时从接口继承的 class 也将其视为依赖项。

我的解决方案如下所示:

InterfaceAssembly
    -IGetData<T>

DataAssembly
    -Repository.CustomerRepository : IGetData<Customer>
    -Repository.ProductRepository : IGetData<Product>
    -Cache.CustomerCache : IGetData<Customer>
    -Cache.ProductCache : IGetData<Product>

我想制作一个安装程序,使 Cache 名称 space 优先于 Repository 名称 space。但是,在 CustomerCache 的情况下,它既实现又依赖 IGetData<Customer>CustomerCache 应注入 CustomerRepository 以满足此依赖性。

有没有一种简单的方法可以处理温莎城堡的这种情况?我是否需要特别注意避免可能被视为循环引用的错误?

这似乎是一个装饰器模式。当以正确的顺序注册时,Castle 会识别装饰器。例如注册时:

container.Register(Component.For<IGetData<Customer>>().ImplementedBy<CustomerCache>());
container.Register(Component.For<IGetData<Customer>>().ImplementedBy<CustomerRepository>());

然后解析 IGetData<Customer> 将 return CustomerCache 修饰 CustomerRepository.