是StaticFactory< T>在$ C ccampserver一个众所周知的模式$? [英] Is the StaticFactory<T> in codecampserver a well known pattern?

查看:255
本文介绍了是StaticFactory< T>在$ C ccampserver一个众所周知的模式$?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

codeCampServer源$ C ​​$ C包含一个通用的 StaticFactory

CodeCampServer source code contains a generic StaticFactory.

我surmising,这是一个关键部分机制的框架内如何使用依赖注入打得很​​好。

I'm surmising that this is a key piece of the mechanism for how the framework plays well with Dependency Injection.

子类使用它的DefaultUnconfiguredState提供静态访问,那么,默认配置状态,为自己而依赖解析机制可以工作的东西取代。

Subclasses of which use it's DefaultUnconfiguredState to provide static access to, well, a Default Unconfigured State for themselves which the dependency resolution mechanism can replace with working stuff.

我一直没能找到任何文档,这...

I've not been able to find any documentation for this...

是否有? (我在等待交付从亚马逊...)

Is there a good explanation in the book? (I'm awaiting delivery from Amazon...)

...或者任何其他人提供良好的评论是什么,这是和我是否会是明智的,采取这种模式(如果它是...)?

...or can anyone else provide a good commentary on what this is and whether I'd be wise to adopt this pattern (if it is one...)?

更新

由于杰弗里巴勒莫回答了这个问题,我看到,在(工作正在进行中)手稿MVC2在行动中这种模式/风格进行了讨论,并使用被用于查找信息库,以保证出厂说明领域层忽略了持久性的担忧。 (见第23章)。

Since Jeffrey Palermo replied to this question I see that in the (work-in-progress) manuscript for MVC2 in Action this pattern/style is discussed and illustrated using a Factory that is used to locate a Repository in order to keep the domain layer ignorant of persistence concerns. (see chapter 23).

在默认情况下使用该工厂将引发异常:

By default the use of this factory throws an exception:

如何创建知识   库不驻留与   厂。这家工厂只   重新presents的能力以返回   资源库

"the knowledge of how to create the repository doesn’t reside with the factory. This factory merely represents the capability to return the repository"

这个例子也可以使用多种机制之一初始化的具体实现库接口。在书中的例子,他们选择不使用IoC容器为了简化和明确一些启动逻辑提供。

The example could have used one of several mechanisms for initializing a concrete implementation of the repository interface. In the example in the book they elect not to use an IOC container for sake of simplicity and provide it explicitly in some start-up logic.

最重要的是,无论是   核心项目还是UI项目   应参照基础设施   项目或库,是纯粹的   基建的性质。我们有   保持NHibernate的完全关闭的   方使的休息   应用程序并不怎么在意数据   访问正在发生的事情

"The important thing is that neither the Core project nor the UI project should reference the Infrastructure project or libraries that are purely infrastructural in nature. We have kept NHibernate completely off to the side so that the rest of the application doesn’t care how the data access is happening"

最后一点需要注意的例子code在这新的一章是该工厂不再是静态的(至少不至于面向外部的接口而言)。

A final point to note about the example code in this new chapter is that the Factory is no longer static (at least not as far as the externally facing interface is concerned).

更新2

巴勒莫先生的博客上一些关于抽象工厂的这一特定的风格(见OrderShipperFactory的implementaion)。

Mr Palermo blogged some more about this particular style of Abstract Factory (see the implementaion of OrderShipperFactory).

我也只考虑手动依赖注入(Bob大叔)。

推荐答案

好问题。我不喜欢它。它应该被命名为StartupFactoryConfiguration,但它是重构行了。

Good question. I don't like it either. It should really be named "StartupFactoryConfiguration", but it is on the refactor list.

我们有这种想法发挥各地,以此来建立DI为通过容器没有构造注射剂项下的地方。

We played around with that idea as a way to set up DI for places that were not under constructor injection via the container.

它会自动消失。我不知道反模式是什么(什么名字?),但StaticFactory会死。

It will go away. I don't know what the anti-pattern is (what name?), but StaticFactory will die.


现在已经更名为今天上午。它现在AbstractFactoryBase。它是抽象工厂模式的实现: http://en.wikipedia.org/wiki /摘要%5Ffactory%5Fpattern

Now it has been renamed as of this morning. It is now AbstractFactoryBase. It is an implementation of the Abstract Factory pattern: http://en.wikipedia.org/wiki/Abstract%5Ffactory%5Fpattern

工厂的实现是最终调用一个IoC contrainer,但它允许从code的地方访问,而装配参考IoC容器组装。

The implementation of the factory is to end up calling an IoC contrainer, but it allows access from a place in code without an assembly reference to the IoC container assembly.

问候, 杰弗里·巴勒莫

Regards, Jeffrey Palermo

这篇关于是StaticFactory< T>在$ C ccampserver一个众所周知的模式$?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆