IFileStream and Windsor Castle

Jan 10, 2012 at 11:26 AM
Edited Jan 10, 2012 at 11:28 AM

Hi

I a bit puzzled about how to use IFileStream with Windsor::Castle....

Lets say I have a Class MyClass

    public class MyClass
    {
        public IFileStream Filestream;

        public int LineCount(string filename)
        {
            var res = 0;
            Filestream.Initialize(filename, FileMode.Open);
            using (var stream = Filestream.FileStreamInstance){
                // Do the counting
            }
            return res;
        }
    }

My main, would be something like:
        public void main()
        {
            var container = new WindsorContainer();
            container.Register(Component.For<IFileStream>().ImplementedBy<FileStreamWrap>());
            container.Register(Component.For<MyClass>());

            var sut= container.Resolve<MyClass>();

            var res= sut.LineCount("whatever");
       }

however when I resolve the MyClass I get a Missing Dependency error... 
it turns out that FileStreamWrap 
doesn't have an empty constructor, so I'll have to supply some kind of stream 
when registering IFIleStream

            container.Register(Component.For<IFileStream>()
                .ImplementedBy<FileStreamWrap>()
                .DependsOn(Property.ForKey("stream")
                .Eq(new MemoryStream()))
                );

which seems rather clumpsy ... or am I missing something here....
TIA

Søren