我总是发现在单元测试中学习如何使用开源项目的最佳方式。 Castle有一个流畅的界面,可以让你在代码中完成任何事情。从WindsorDotNet2Tests测试用例:
[Test]
public void ParentResolverIntercetorShouldNotAffectGenericComponentInterceptor()
{
WindsorContainer container = new WindsorContainer();
container.AddComponent<MyInterceptor>();
container.Register(
Component.For<ISpecification>()
.ImplementedBy<MySpecification>()
.Interceptors(new InterceptorReference(typeof(MyInterceptor)))
.Anywhere
);
container.AddComponent("repos", typeof(IRepository<>), typeof(TransientRepository<>));
ISpecification specification = container.Resolve<ISpecification>();
bool isProxy = specification.Repository.GetType().FullName.Contains("Proxy");
Assert.IsFalse(isProxy);
}
而对于更多的,检查出的ComponentRegistrationTestCase和AllTypesTestCase
还为做一个DSL,这是我的首选选项,因为它确实简化了操作,并提供很容易扩展。 DSL被称为Binsor,您可以在这里阅读更多信息:http://www.ayende.com/Blog/archive/7268.aspx但是,infor最好的地方是单元测试。这是什么可能的binsor一个代码示例:
for type in AllTypesBased of IController("Company.Web.Controller"):
component type
这两个行会永远注册键入继承了一个IController接口放入容器:d
多谢多谢了精彩的响应!我将不得不深入研究它。 WindsorContaienr上的.Register方法来自哪里?我没有通过我的intellisense看到它。它是一种扩展方法吗? – 2008-09-18 15:26:13