Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 为什么赢了';难道温莎城堡没有注册什么吗?_.net_Dependency Injection_Inversion Of Control_Castle Windsor - Fatal编程技术网

.net 为什么赢了';难道温莎城堡没有注册什么吗?

.net 为什么赢了';难道温莎城堡没有注册什么吗?,.net,dependency-injection,inversion-of-control,castle-windsor,.net,Dependency Injection,Inversion Of Control,Castle Windsor,这只是我写这篇文章的70种不同方式之一。它们中没有一个有效。没有注册任何东西。曾经如果我继续做显式注册(Component.For等),这个小小的测试应用程序工作得很好,但我想,“嘿,让我们用简单的方法来做吧……” 我已经用“简单”的方式做了一个小时了。我所要展示的就是: 其他信息:未找到支持WindsorTestApp.IPrimeSequenceGenerator服务的组件 是的,有一个类实现了该接口。container.Register(Classes.FromThisAssembly()

这只是我写这篇文章的70种不同方式之一。它们中没有一个有效。没有注册任何东西。曾经如果我继续做显式注册(Component.For等),这个小小的测试应用程序工作得很好,但我想,“嘿,让我们用简单的方法来做吧……”

我已经用“简单”的方式做了一个小时了。我所要展示的就是:

其他信息:未找到支持WindsorTestApp.IPrimeSequenceGenerator服务的组件

是的,有一个类实现了该接口。

container.Register(Classes.FromThisAssembly().Pick())
        container.Register(
            Classes.FromThisAssembly()
            .Pick()
            .WithService
            .DefaultInterfaces()
            .LifestyleTransient());
.Configure(component=>component.LifestyleTransient()) .ConfigureFor(组件=>component.LifestyleSingleton()) .WithServiceFirstInterface());
现在完全可以注册所有内容了。我遇到的两个问题是:

1) 为了自动注册,组件名称必须与接口名称匹配,接口名称前面的小I除外。编辑:您选择的约定可能决定这是否正确


2) 显然,这些组件不仅需要容器可以访问,而且还需要是公共的。可能还有其他选项可以使用,但private肯定不行。

程序集中是否有任何类实际实现了
IPrimeSequenceGenerator
?部分答案:IPrimeSequenceGenerator的实现名为PrimeGenerator,而不是PrimeSequenceGenerator。如果我弄清楚为什么其余的也不起作用,就会更新。
        container.Register(Classes.FromThisAssembly().Pick()
            .Configure(component => component.LifestyleTransient())
            .ConfigureFor<IPrimeValidator>(component => component.LifestyleSingleton())
            .WithServiceFirstInterface());