温莎城堡 - 如何创建安装程序来处理多级依赖结构



我有一个案例,几个不同的类从同一个接口继承。此外,有时从接口继承的类也会将其作为依赖项。

我的解决方案如下所示:

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

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

有没有简单的方法来处理温莎城堡的这种情况?我是否必须特别注意避免它可能认为是循环引用的错误?

这似乎是一种装饰器模式。城堡在以正确的顺序注册时识别装饰者。例如,注册时,例如:

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

然后解决IGetData<Customer>将返回装饰CustomerRepositoryCustomerCache

相关内容

最新更新