Castle Windsor: How to prevent circular references in factory-created objects were the created objects refers back to the factory

狂风中的少年 提交于 2019-12-06 15:05:08

I would simply move the factory out of the constructors of the various specific object creators, and introduce a method on the IObjectCreator interface instead, responsible for initialising the creators:

public interface IObjectCreator
{
    T CreateObject<T>(IDataRow data);
    bool SupportsType(Type type);
    void Initialize(IObjectCreatorFactory factory);
}

And then just invoke Initialze(this) on each object creator passed into the factory.

In the past I've used custom life cycle stages to take care of automatically invoking "post-construction" setup of components to both avoid circular dependencies and also to take care of other associated concerns (i.e. applying additional component configuration from an external source like a database) - but it's probably overkill for what you need.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!