English 中文(简体)
城堡风窗中的多个装饰模式
原标题:Multiple Decorator pattern in castle-windsor

我们正在重新设计一些遗留软件,以便更能测试,我们已决定采用依赖注射和城堡。

First, our goal: * A number of decorators that all work on a data stream. * Multiple combinations of the decorators are possible and the root nodes in each case can be required to get data from different places.

从技术上讲,我们的设计如下:

interface IUpdateableValue<T> 
{
  T Get();
};

例如,我们有三套数据需要检索,其中包括若干组成部分,所有执行的InatedableValue ()(Pseudo-code):

JsonParser(
    Decompressor(
        Decrypter(decryptionKey
            FileCache(filename, 
                HttpWebDownloader(url))))

XmlParser(
    Decompressor(
        Decrypter(decryptionKey2
            FileCache(filename2, 
                HttpWebDownloader(url2))))

我很难把设计设计出适合像城堡风景那样的DI框架。我怀疑有些设计可以由有名的例子来处理,但这种用法似乎有味道。

例如JsonParser和XmlParser案例的“用户”不知道(或关心)数据来自Httpurl、文件还是神奇地摘出帽子。

我想我们的设计有问题 但不确定怎么解决

有关于如何进步的想法吗?

问题回答

与 Castle Windsor, 您可以以正确的顺序注册, 暗含设置计分器 。 您需要首先注册外部计分器 :

container.Register(Component
  .For<IUpdateableValue>()
  .ImplementedBy<JsonParser>());
container.Register(Component
  .For<IUpdateableValue>()
  .ImplementedBy<Decompressor>());
container.Register(Component
  .For<IUpdateableValue>()
  .ImplementedBy<Decrypter>());
...

当您解决 I Uniteddable Value Castue Windsor 时, 将自动连接依赖关系, 因此它们被正确嵌套 。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签