Search code examples
c#castle-windsor

ComponentNotFoundException Castle Windsor


Here is my 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
            );
    }
}

Here is my 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();

This is console application. I get this exception :

{"No component for supporting the service Reveal.Domain.Location.Service.Read.IServiceReadCity was found"} At this line :

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

Can you tell me what I'm doing wrong and how to fix this? Thanks.


Solution

  • Installers in Windsor need to be publicly accessible as Windsor looks for public types implementing the IWindsorInstaller interface.

    Making the installer public should fix the issue