【发布时间】:2013-12-31 07:39:10
【问题描述】:
这段代码:
public void Install(IWindsorContainer container, IConfigurationStore store)
{
container.Register(AllTypes.FromThisAssembly()
//AllTypes.FromAssemblyNamed("Acme.Crm.Data")
.Where(type => type.Name.EndsWith("Repository"))
.WithService.DefaultInterfaces()
.Configure(c => c.LifeStyle.PerWebRequest));
}
...从官方文档here 派生/改编,失败了,“只有赋值、调用、递增、递减、等待和新对象表达式可以用作语句 em>"
我犯了什么错误?还是官方文档误导了我?
更新
应西蒙·怀特黑德的要求,这是整个班级:
using Castle.MicroKernel.Registration;
using Castle.MicroKernel.SubSystems.Configuration;
using Castle.Windsor;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Castle.MicroKernel.Lifestyle;
namespace HandheldServer.DIInstallers
{
public class RepositoriesInstaller : IWindsorInstaller
{
public void Install(IWindsorContainer container, IConfigurationStore store)
{
container.Register(//Classes.FromThisAssembly()
//AllTypes.FromAssemblyNamed("Acme.Crm.Data")
AllTypes.FromThisAssembly()
.Where(type => type.Name.EndsWith("Repository"))
.WithService.DefaultInterfaces()
//.Configure(c => c.LifeStyle.PerWebRequest));
.Configure(c => c.LifeStyle.PerWebRequest));
}
}
}
【问题讨论】:
-
看起来不错。问题可能出在文件中的其他地方。你能告诉我们整个源文件吗?
-
好的,不过就是这样。
标签: c# dependency-injection asp.net-web-api castle-windsor asp.net-web-api-routing