Spring .Net配置流畅 [英] Spring .Net Configuration Fluently

查看:155
本文介绍了Spring .Net配置流畅的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在项目中使用Spring .Net,并且正在探索配置选项。所有我可以找到关于配置为Spring .Net是配置文件的东西。 Spring支持配置代码吗?我已经使用了Castle和Ninject,而且两者似乎都是本来提供的。我已经找到了要求增加支持的项目,但是我不想要一些在6个月内死亡的项目。我已经在博客中找到了参考,似乎表明Spring支持这一点,但是我找不到任何文档!!

I have the need to use Spring .Net in a project and am exploring configuration options. All I can find about config for Spring .Net is config file stuff. Does Spring support configuration in code? I have used Castle and Ninject, and both seem to offer this natively. I have found projects that claim to add support, but I dont want some knock off project that will die in 6 months. I have found references in blogs that seem to indicate Spring supports this but I cant find any documentation!!

这可能是您推荐的第2部分。知道它不能支持流畅的配置?我知道这两个都是伟大的IoC容器,但是我已经处理了有关Spring配置的大量配置文件的项目,我讨厌它。

Part 2 of this might be would you recommend Spring .Net over Windsor knowing it cant support fluent configuration? I know both are great IoC containers, but I have worked on projects that have massive config files for Spring configuration and I hate it.

推荐答案

p>否,Spring.NET 的当前版本(1.3)仅支持XML 配置。在未来的版本中,一直在讨论支持Code as Configuration的代码,但这还没有实现。

No, the current version (1.3) of Spring.NET only supports XML configuration. There has been talk about supporting Code as Configuration in future versions, but this has not yet materialized.

在我看来, Castle Windsor远远优于到Spring.NET。我不能想到温莎城堡没有的Spring.NET的一个功能。另一方面,温莎城堡具有以下在Spring.NET中不可用的功能:

In my opinion, Castle Windsor is far superior to Spring.NET. I can't think of a single feature of Spring.NET that Castle Windsor doesn't have. On the other hand, Castle Windsor has the following features that are not available in Spring.NET:


  • 代码作为配置

  • 基于公约的配置

  • 更多生命周期

  • 自定义生命周期

  • 对象图退役

  • 将接口/基类显式映射到具体类型

  • 基于类型的解析

  • 模块化配置安装人员)

  • 内置对装饰器的支持

  • 键入工厂

  • Code as Configuration
  • Convention-based configuration
  • More lifetimes
  • Custom lifetimes
  • Object graph decommissioning
  • Explicit mapping of interfaces/base classes to concrete types
  • Type-based resolution
  • Modular configuration (Installers)
  • Built-in support for Decorators
  • Typed Factories

可能还有其他功能我忘了...

There are probably other features I forgot about...

看来我有点太快了在这里的触发器上,虽然对我来说,Spring.NET的文档还指出,目前版本中只有XML配置。

It appears I was a bit too quick on the trigger here, although to my defense, the Spring.NET documentation also states that there's only XML configuration in the current version.

但是,事实证明,如果某些上下文,一个非常原始的API是可用的,使您能够配置没有XML的上下文。这里有一个例子:

However, it turns out that if for certain contexts, a very primitive API is available that enables you to configure a context without XML. Here's an example:

var context = new GenericApplicationContext();
context.RegisterObjectDefinition("EggYolk", 
    new RootObjectDefinition(typeof(EggYolk)));
context.RegisterObjectDefinition("OliveOil",
    new RootObjectDefinition(typeof(OliveOil)));
context.RegisterObjectDefinition("Mayonnaise", 
    new RootObjectDefinition(typeof(Mayonnaise), 
        AutoWiringMode.AutoDetect));

请注意这个API如何非常贴近XML配置模式。因此,您不会从 IObjectDefinitionRegistry 接口获得任何流畅的API,但至少有一个与XML分离的API。至少在理论上可以构建一个流利的API。

Notice how this API very closely mirrors the XML configuration schema. Thus, you don't get any fluent API from the IObjectDefinitionRegistry interface, but at least there's an API which is decoupled from XML. Building a fluent API on top of this is at least theoretically possible.

这篇关于Spring .Net配置流畅的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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