ComponentNotFoundException Castle Windsor

时间:2016-10-03 09:01:49

标签: c# castle-windsor

这是我的Installer.cs:

class Installer : IWindsorInstaller
{
    public void Install(IWindsorContainer container, IConfigurationStore store)
    {
        container
            .Register(Component.For<IDbContext>()
            .ImplementedBy<ApplicationDbContext>()
            .LifeStyle.PerThread
            );

        container
            .Register(Component.For(typeof(IRepository<>))
            .ImplementedBy(typeof(Repository<>))
            .LifeStyle.PerThread
            );

        container
            .Register(Component.For<IServiceReadCity>()
            .ImplementedBy<ServiceReadCity>()
            .LifeStyle.PerThread
            );
    }
}

这是我的Program.cs:

SqlServerTypes.Utilities.LoadNativeAssemblies(AppDomain.CurrentDomain.BaseDirectory);
System.Data.Entity.SqlServer.SqlProviderServices.SqlServerTypesAssemblyName = "Microsoft.SqlServer.Types, Version=12.0.0.0, Culture=neutral, PublicKeyToken=898989899898989898";

var container = new WindsorContainer();

container.Install(FromAssembly.This());
IServiceReadCity _cityReadService = container.Resolve<IServiceReadCity>();

var cities = _cityReadService.GetListQuery();

这是控制台应用程序。我得到了这个例外:

  

{&#34;没有支持该服务的组件   找到了Reveal.Domain.Location.Service.Read.IServiceReadCity&#34;}    在这一行:

IServiceReadCity _cityReadService = container.Resolve<IServiceReadCity>();

你能告诉我我做错了什么以及如何解决这个问题?感谢。

1 个答案:

答案 0 :(得分:1)

Windsor的安装人员需要公开访问,因为Windsor会查找实现"autoload": { "classmap": [ "app/providers" ] }, 界面的公共类型。

制作安装程序IWindsorInstaller应解决问题