Search code examples
c#dependency-injectioncastle-windsor

Windsor dependency injection with parameter in ctor


I'm trying to configure Castle Windsor

I have a IFileReader interface implemented by FileReader, and FileReader has a string property in the constructor

How can I set this property when I'm trying to get an instance of FileReader with a ServiceLocator?

Container.Register(Component.For<IFileReader>().ImplementedBy<FileReader>());

public class FileReader
{
public FileReader(string fileName)
.
.
.

ServiceLocator.Current.GetInstance<IFileReader>(); <- how pass filename??

Solution

  • We were having a discussion in the Alt.Net Hispano group about this topic.

    Here is the link (spanish) if anyone is interested http://groups.google.com/group/altnet-hispano/browse_thread/thread/5880f9e9fe5b5da4/200443a0b9e99040?show_docid=200443a0b9e99040

    Basically, you can't do what I want to do :P