Trying to make use of the Castle Windsor IoC. I have a very simple application. My interfaces exist in Test.Services namespace. I get the following exception when compiling:
"The type name Test.Services.IParse, Test.Services could not be located"
This is my app.config:
<configuration>
<configSections>
<section name="castle"
type="Castle.Windsor.Configuration.AppDomain.CastleSectionHandler,
Castle.Windsor" />
</configSections>
<castle>
<components>
<component id="HtmlTitleRetriever"
type="Test.HTMLTitleRetriever, Test">
</component>
<component id="FileParser"
service="Test.Services.IParse, Test.Services"
type="Test.FileParser,
Test">
</component>
<component id="FileDownloader"
service="Test.Services.IDownload, Test.Services"
type="Test.FileDownloader, Test">
</component>
</components>
</castle>
Can someone tell me what I'm missing?
Thanks
-Nick
Is the IParse interface in the Test.Services assembly (Test.Services.dll) ?
The format used to define type names in the config is the same you can get from the AssemblyQualifiedName property of the type. In a nutshell, it's:
Namespace.Type, Assembly.
For generic types, see this.
Doing the following in code works. I would like to use a Config file though so changes do not need to be recompiled each time.
I had the same issue and Eric's solution worked to resolve the problem. I Created a "Domain Models" Project and then later renamed it to "DomainModel" I though I changed all the references but then looking in the bin folder the assembly was still called "Domain Models" thats why castle windsor could not find it.
Stupid question, but are you certain that the assembly containing the class you register gets actually copied to the output directory?
Almost Nick! You need to pass the xml configuration into the constructor of WindsorContainer:
I ran into this "Got ya" as well when I first started playing with Castle Windsor. It does not know to look into the configuration section.
Tip: go get the latest from their trunk. There's a new method called Register that is really useful for mass-registering multiple classes on the same interface. I.e., if you are developing with ASP.NET MVC, and you have a bunch of IController, you can use Castle Windsor to auto-register them for you. So, you do not have to specify them in the configuration file!